<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.yoctoproject.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tzanussi</id>
	<title>Yocto Project - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.yoctoproject.org/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tzanussi"/>
	<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/Special:Contributions/Tzanussi"/>
	<updated>2026-04-07T21:52:04Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.5</generator>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Poky-Tiny&amp;diff=19748</id>
		<title>Poky-Tiny</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Poky-Tiny&amp;diff=19748"/>
		<updated>2016-08-04T19:39:15Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Invoking qemu with poky-tiny images */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Poky-tiny is a variant of the poky distribution which is stripped down to minimal configuration.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
It is intended to be useful for a few different purposes:&lt;br /&gt;
* as a demonstration of techniques useful for reducing other images&lt;br /&gt;
* as a springboard for very low-end distributions and images&lt;br /&gt;
* as a place to experiment with whole-system optimization techniques&lt;br /&gt;
&lt;br /&gt;
It was written by Darren Hart.&lt;br /&gt;
&lt;br /&gt;
=== Basic use ===&lt;br /&gt;
To use the poky-tiny distro, adjust the DISTRO setting in your conf/local.conf file.&lt;br /&gt;
That is, set it to: &amp;quot;DISTRO=poky-tiny&amp;quot;&lt;br /&gt;
&lt;br /&gt;
poky-tiny does not include a target-side package manager, so it is useful, to avoid&lt;br /&gt;
extra dependencies, to use it with the IPKG package management scheme.  This is the lightest-weight&lt;br /&gt;
package management scheme.  Set this in your conf/local.conf file:&lt;br /&gt;
 PACKAGE_CLASSES ?= &amp;quot;package_ipk&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Then do a basic build of the system:&lt;br /&gt;
 $ bitbake core-image-minimal&lt;br /&gt;
&lt;br /&gt;
Resulting images should appear in your &amp;lt;build-dir&amp;gt;/tmp/deploy/images directory.&lt;br /&gt;
&lt;br /&gt;
== FAQ ==&lt;br /&gt;
* where is poky-tiny defined?&lt;br /&gt;
** poky-tiny is defined in &amp;lt;yocto-dir&amp;gt;/meta-yocto/conf/distro/poky-tiny.conf.  Some other recipes and images have been modified to support the features in poky-tiny.&lt;br /&gt;
** The kernel recipe for poky-tiny is in &amp;lt;yocto-dir&amp;gt;/meta/recipes-kernel/linux/linux-yocto-tiny_x.x.bb&lt;br /&gt;
* What images are supported?&lt;br /&gt;
** As of poky-danny-8.0 (the 1.3 release of yocto), poky-tiny.conf defined the following images: IMAGE_FSTYPES = &amp;quot;ext2 cpio.gz&amp;quot;  This means it will build both an ext2 filesystem image, and a cpio.gz image (suitable for use as an initramfs).&lt;br /&gt;
* What machines are supported (are there any restrictions)?&lt;br /&gt;
** in the kernel recipe file, it has COMPATIBLE_MACHINE=&amp;quot;(qemux86)&amp;quot;&lt;br /&gt;
* What features have been eliminated?&lt;br /&gt;
* What is the size difference between poky-tiny and poky (core-image-minimal)?&lt;br /&gt;
* Are there differences in the way poky-tiny is customized, from the way default &#039;poky&#039; is customized? (eg. gotchas for adding to IMAGE_INSTALL or IMAGE_FEATURES)?&lt;br /&gt;
&lt;br /&gt;
== Creating your own tiny-based distro ==&lt;br /&gt;
You can create your own distro, based on the tiny work, by copying the poky-tiny.conf file&lt;br /&gt;
to your own layer, and editing it from there.&lt;br /&gt;
&lt;br /&gt;
Assuming you are calling your layer &#039;meta-foo&#039;, you could do the following:&lt;br /&gt;
&lt;br /&gt;
* create your meta-foo layer (see other docs for this)&lt;br /&gt;
* copy the poky-tiny distro configuration file to your own layer&lt;br /&gt;
 $ install -p meta-foo/conf/distro&lt;br /&gt;
 $ cp meta-yocto/conf/distro/poky-tiny.conf meta-foo/conf/distro/foo-tiny.conf&lt;br /&gt;
* edit your conf/local.conf to use your foo-tiny.conf distro&lt;br /&gt;
 $ vi &amp;lt;build-dir&amp;gt;/conf/local.conf&lt;br /&gt;
 [change it so &amp;quot;DISTRO?=foo-tiny&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
== Adjusting poky-tiny ==&lt;br /&gt;
=== Controlling LIBC features ===&lt;br /&gt;
Inside foo-tiny.conf (derived from poky-tiny.conf), you can specify what LIBC features to support&lt;br /&gt;
by modifying the DISTRO_FEATURES_LIBC variable.&lt;br /&gt;
&lt;br /&gt;
This variable is declared to be a space-separated list of other DISTRO_FEATURES_LIBC_xxx variables.&lt;br /&gt;
To turn on or off features in libc, edit the values of these variables.&lt;br /&gt;
&lt;br /&gt;
==== eglibc ====&lt;br /&gt;
To see different options that are available, see the file:&lt;br /&gt;
&amp;lt;yocto-dir&amp;gt;/meta/recipes-core/eglibc/eglibc-options.inc&lt;br /&gt;
&lt;br /&gt;
Listed in that file are the routines: distro_features_check_deps() and features_to_eglibc_settings(),&lt;br /&gt;
which map items listed in DISTRO_FEATURES_LIBC into specific eglibc settings.&lt;br /&gt;
&lt;br /&gt;
==== uclibc ====&lt;br /&gt;
To see different options that are available, see the file:&lt;br /&gt;
&amp;lt;yocto-dir&amp;gt;/meta/recipes-core/uclibc/uclibc-config.inc&lt;br /&gt;
&lt;br /&gt;
Listed in that file is the routine: features_to_uclibc_settings(),&lt;br /&gt;
which maps items listed in DISTRO_FEATURES_LIBC into specific uclibc settings.&lt;br /&gt;
&lt;br /&gt;
=== Controlling kernel features ===&lt;br /&gt;
&lt;br /&gt;
=== Controlling busybox features ===&lt;br /&gt;
To adjust busybox features, it&#039;s necessary to have your own defconfig. Then the busybox recipe must be appended (or you need your own busybox recipe) to tell bitbake where it can find this defconfig. An example: &lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;$ cd /path/to/poky/directory/meta-new-layer&#039;&#039;&#039;&lt;br /&gt;
 &#039;&#039;&#039;$ tree recipes-core/&#039;&#039;&#039;&lt;br /&gt;
 recipes-core/&lt;br /&gt;
 ├── busybox_1.20.2&lt;br /&gt;
 │   └── defconfig&lt;br /&gt;
 └── busybox_1.20.2.bbappend&lt;br /&gt;
 1 directory, 2 files&lt;br /&gt;
 &#039;&#039;&#039;$ cat recipes-core/busybox_1.20.2.bbappend&#039;&#039;&#039; &lt;br /&gt;
 FILESEXTRAPATHS_prepend := &amp;quot;${THISDIR}/${PN}:&amp;quot;&lt;br /&gt;
 PACKAGES =+ &amp;quot;${PN}-mdev&amp;quot;&lt;br /&gt;
 &#039;&#039;&#039;$ diff recipes-core/busybox_1.20.2/defconfig ../meta/recipes-core/busybox/busybox-1.20.2/defconfig&#039;&#039;&#039; &lt;br /&gt;
 530d529&lt;br /&gt;
 &amp;lt; CONFIG_MDEV=y&lt;br /&gt;
 536d534&lt;br /&gt;
 &amp;lt; CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y&lt;br /&gt;
&lt;br /&gt;
In this example you can see how in a new layer, the busybox_&amp;lt;version&amp;gt;.bbappend file modifies the FILESEXTRAPATHS, which enables bitbake to find the corresponding defconfig in meta-new-layer/recipes-core/busybox_1.20.2. In the example defconfig, mdev gets enabled by setting the variables CONFIG_MDEV and CONFIG_FEATURE_MDEV_LOAD_FIRMWARE. The original defconfig that would be used by poky normally is stored in meta/recipes-core/busybox/busybox-&amp;lt;version&amp;gt;/defconfig as of this writing. PACKAGES += just makes sure that busybox-mdev gets packaged because it doesn&#039;t do this by default.&lt;br /&gt;
&lt;br /&gt;
In general: Set the FILESEXTRAPATHS so bitbake finds your defconfig and put whatever you like into your defconfig.&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting the build ==&lt;br /&gt;
&lt;br /&gt;
== Invoking qemu with poky-tiny images ==&lt;br /&gt;
runqemu can be used to run a poky-tiny image.  For instance, for a poky-tiny qemux86 build, try:&lt;br /&gt;
&lt;br /&gt;
  $ runqemu qemux86 ramfs&lt;br /&gt;
&lt;br /&gt;
If that doesn&#039;t work, try executing qemu directly instead.  Here&#039;s the template:&lt;br /&gt;
&lt;br /&gt;
 $ qemu-system-i386 -kernel path/to/kernel -initrd path/to/image.cpio.gz -nographic -append &amp;quot;console=ttyS0 root=/dev/ram0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Here the actual full command I used:&lt;br /&gt;
&lt;br /&gt;
 $ tmp/sysroots/x86_64-linux/usr/bin/qemu-system-i386 -kernel tmp/deploy/images/qemux86/bzImage-qemux86.bin -initrd tmp/deploy/images/qemux86/core-image-minimal-qemux86.cpio.gz -nographic -append &amp;quot;console=ttyS0 root=/dev/ram0&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Some information about the running system ===&lt;br /&gt;
You can poke around, and see the status of various things.  &#039;ps&#039; shows only 22 processes running, with only 3 user-space (ie not kernel threads):&lt;br /&gt;
&lt;br /&gt;
 # ps | grep -v [[]&lt;br /&gt;
  PID USER       VSZ STAT COMMAND&lt;br /&gt;
    1 root      2004 S    {init} /bin/sh /init&lt;br /&gt;
   38 root      2144 S    sh&lt;br /&gt;
   41 root      2144 R    ps&lt;br /&gt;
&lt;br /&gt;
So... busybox is really the only executable on the system, and it is providing /bin/sh.  /init is a shell script,&lt;br /&gt;
which will run /etc/rc.local, if one is present.  There&#039;s a sample in /etc/rc.local.sample that you can use as a&lt;br /&gt;
starting point to customize the init process.  If you turn on packages in yocto, there will be init scripts deposited&lt;br /&gt;
in /etc/init.d, which you can call from either /init or /etc/rc.local to invoke (none of that fancy sysV rc init scripts here!)&lt;br /&gt;
&lt;br /&gt;
I booted with mem=24M (that was about as small as I could go) and saw the following memory utilization:&lt;br /&gt;
 # free&lt;br /&gt;
             total         used         free       shared      buffers&lt;br /&gt;
 Mem:         19724         5944        13780            0            0&lt;br /&gt;
 -/+ buffers:               5944        13780&lt;br /&gt;
 Swap:            0            0            0&lt;br /&gt;
&lt;br /&gt;
The filesystem is a little over 3M in size:&lt;br /&gt;
 # du -sh /&lt;br /&gt;
 3.2M	/&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a sample of what the filesystem looks like (as of yocto-danny-8.0), with results sorted by size&lt;br /&gt;
and /sys, /proc and /dev omitted:&lt;br /&gt;
 # find / -type f -xdev | xargs ls -laSr&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 21:24 /lib/modules/3.4.11-yocto-tiny/modules.dep&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 21:24 /lib/modules/3.4.11-yocto-tiny/modules.builtin.bin&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 00:45 /etc/network/nm-disabled-eth0&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 00:45 /etc/motd&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 00:14 /etc/ld.so.conf&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 00:45 /etc/default/usbd&lt;br /&gt;
 -rw-r--r--    1 root     root             6 Nov 14 22:05 /var/volatile/run/ifstate&lt;br /&gt;
 -rw-r--r--    1 root     root             8 Nov 14 00:45 /etc/hostname&lt;br /&gt;
 -rw-r--r--    1 root     root            12 Nov 14 21:24 /lib/modules/3.4.11-yocto-tiny/modules.symbols.bin&lt;br /&gt;
 -rw-r--r--    1 root     root            12 Nov 14 21:24 /lib/modules/3.4.11-yocto-tiny/modules.dep.bin&lt;br /&gt;
 -rw-r--r--    1 root     root            12 Nov 14 21:24 /lib/modules/3.4.11-yocto-tiny/modules.alias.bin&lt;br /&gt;
 -rw-r--r--    1 root     root            13 Nov 14 21:24 /etc/version&lt;br /&gt;
 -rw-r--r--    1 root     root            13 Nov 14 21:24 /etc/timestamp&lt;br /&gt;
 -rw-r--r--    1 root     root            26 Nov 14 00:45 /etc/host.conf&lt;br /&gt;
 -rw-r--r--    1 root     root            38 Nov 14 00:45 /etc/filesystems&lt;br /&gt;
 -rw-r--r--    1 root     root            44 Nov 14 00:45 /etc/hosts&lt;br /&gt;
 -rw-r--r--    1 root     root            45 Nov 14 21:24 /lib/modules/3.4.11-yocto-tiny/modules.alias&lt;br /&gt;
 -rwxr-xr-x    1 root     root            49 Nov 14 00:22 /usr/share/udhcpc/default.script&lt;br /&gt;
 -rw-r--r--    1 root     root            49 Nov 14 21:24 /lib/modules/3.4.11-yocto-tiny/modules.symbols&lt;br /&gt;
 -rw-r--r--    1 root     root            52 Nov 14 21:24 /lib/modules/3.4.11-yocto-tiny/modules.devname&lt;br /&gt;
 -rw-r--r--    1 root     root            72 Nov 14 00:45 /etc/issue.net&lt;br /&gt;
 -rw-r--r--    1 root     root            74 Nov 14 00:45 /etc/issue&lt;br /&gt;
 -rwxr-xr-x    1 root     root            93 Nov 13 20:19 /etc/default/devpts&lt;br /&gt;
 -rw-r--r--    1 root     root           109 Nov 14 00:45 /etc/shells&lt;br /&gt;
 -rw-r--r--    1 root     root           131 Nov 14 21:24 /lib/modules/3.4.11-yocto-tiny/modules.softdep&lt;br /&gt;
 -rw-r--r--    1 root     root           132 Nov 14 00:45 /etc/network/interfaces&lt;br /&gt;
 -rwxr-xr-x    1 root     root           152 Nov 14 00:45 /etc/skel/.profile&lt;br /&gt;
 -rwxr-xr-x    1 root     root           270 Nov 13 20:19 /etc/init.d/hostname.sh&lt;br /&gt;
 -rwxr-xr-x    1 root     root           289 Nov 13 20:19 /etc/init.d/reboot&lt;br /&gt;
 -rwxr-xr-x    1 root     root           321 Nov 13 20:19 /etc/init.d/save-rtc.sh&lt;br /&gt;
 -rwxr-xr-x    1 root     root           410 Nov 14 00:45 /etc/skel/.bashrc&lt;br /&gt;
 -rwxr-xr-x    1 root     root           438 Nov 13 20:19 /etc/init.d/sendsigs&lt;br /&gt;
 -rw-r--r--    1 root     root           446 Nov 14 21:23 /etc/group&lt;br /&gt;
 -rw-r--r--    1 root     root           465 Nov 14 00:45 /etc/nsswitch.conf&lt;br /&gt;
 -rwxr-xr-x    1 root     root           473 Nov 14 21:24 /init&lt;br /&gt;
 -rwxr-xr-x    1 root     root           492 Nov 13 20:19 /etc/init.d/banner.sh&lt;br /&gt;
 -rwxr-xr-x    1 root     root           510 Nov 13 20:19 /etc/init.d/halt&lt;br /&gt;
 -rwxr-xr-x    1 root     root           516 Nov 13 20:19 /etc/init.d/umountfs&lt;br /&gt;
 -rwxr-xr-x    1 root     root           526 Nov 13 20:19 /etc/init.d/devpts.sh&lt;br /&gt;
 -rwxr-xr-x    1 root     root           578 Nov 13 20:19 /etc/init.d/single&lt;br /&gt;
 -rwxr-xr-x    1 root     root           585 Nov 13 20:19 /etc/init.d/rmnologin.sh&lt;br /&gt;
 -rw-r--r--    1 root     root           586 Nov 14 00:20 /usr/share/run-postinsts/run-postinsts.awk&lt;br /&gt;
 -rwxr-xr-x    1 root     root           609 Nov 14 00:20 /etc/init.d/run-postinsts&lt;br /&gt;
 -rwxr-xr-x    1 root     root           632 Nov 14 00:45 /etc/rc.local.sample&lt;br /&gt;
 -rw-r--r--    1 root     root           651 Nov 14 00:22 /etc/syslog-startup.conf.busybox&lt;br /&gt;
 -rwxr-xr-x    1 root     root           660 Nov 13 20:19 /etc/init.d/sysfs.sh&lt;br /&gt;
 -rw-r--r--    1 root     root           704 Nov 14 00:45 /etc/fstab&lt;br /&gt;
 -rwxr-xr-x    1 root     root           711 Nov 13 20:19 /etc/init.d/umountnfs.sh&lt;br /&gt;
 -rw-r--r--    1 root     root           719 Nov 14 21:23 /etc/passwd&lt;br /&gt;
 -rw-------    1 root     root           737 Nov 14 22:22 /.ash_history&lt;br /&gt;
 -rw-r--r--    1 root     root           783 Nov 14 21:24 /etc/ld.so.cache&lt;br /&gt;
 -rwxr-xr-x    1 root     root           809 Nov 14 00:45 /etc/network/if-pre-up.d/nfsroot&lt;br /&gt;
 -rw-------    1 root     root           836 Nov 14 21:24 /var/volatile/cache/ldconfig/aux-cache&lt;br /&gt;
 -rw-r--r--    1 root     root           847 Nov 14 00:45 /etc/profile&lt;br /&gt;
 -rwxr-xr-x    1 root     root           859 Nov 13 20:19 /etc/init.d/mountall.sh&lt;br /&gt;
 -rwxr-xr-x    1 root     root           878 Nov 14 00:45 /etc/init.d/modutils.sh&lt;br /&gt;
 -rw-r--r--    1 root     root           887 Nov 14 00:45 /etc/rpc&lt;br /&gt;
 -rw-r--r--    1 root     root          1123 Nov 13 20:19 /etc/init.d/functions.initscripts&lt;br /&gt;
 -rwxr-xr-x    1 root     root          1349 Nov 13 20:19 /etc/init.d/urandom&lt;br /&gt;
 -rwxr-xr-x    1 root     root          1540 Nov 13 20:19 /etc/init.d/mountnfs.sh&lt;br /&gt;
 -rw-r--r--    1 root     root          1633 Nov 14 00:45 /etc/inputrc&lt;br /&gt;
 -rwxr-xr-x    1 root     root          1711 Nov 14 00:22 /etc/init.d/syslog.busybox&lt;br /&gt;
 -rw-r--r--    1 root     root          1740 Nov 13 20:19 /etc/default/volatiles/00_core&lt;br /&gt;
 -rwxr-xr-x    1 root     root          1752 Nov 13 20:19 /etc/init.d/bootmisc.sh&lt;br /&gt;
 -rwxr-xr-x    1 root     root          1909 Nov 14 00:45 /etc/init.d/networking&lt;br /&gt;
 -rw-r--r--    1 root     root          2146 Nov 14 00:22 /etc/busybox.links&lt;br /&gt;
 -rwxr-xr-x    1 root     root          2514 Nov 14 00:22 /etc/init.d/hwclock.sh&lt;br /&gt;
 -rwxr-xr-x    1 root     root          2548 Nov 14 00:22 /etc/udhcpc.d/50default&lt;br /&gt;
 -rw-r--r--    1 root     root          2933 Nov 14 00:45 /etc/protocols&lt;br /&gt;
 -rwxr-xr-x    1 root     root          3229 Nov 13 20:19 /etc/init.d/checkroot.sh&lt;br /&gt;
 -rwxr-xr-x    1 root     root          4409 Nov 13 20:16 /usr/sbin/update-rc.d&lt;br /&gt;
 -rwxr-xr-x    1 root     root          4524 Nov 14 00:45 /usr/bin/update-alternatives&lt;br /&gt;
 -rwxr-xr-x    1 root     root          5249 Nov 13 20:19 /etc/init.d/populate-volatile.sh&lt;br /&gt;
 -rwxr-xr-x    1 root     root          6666 Nov 13 20:19 /etc/device_table&lt;br /&gt;
 -rwsr-xr-x    1 root     root          9544 Nov 14 00:14 /usr/lib/eglibc/pt_chown&lt;br /&gt;
 -rwxr-xr-x    1 root     root          9740 Nov 14 00:14 /lib/libutil-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root         13828 Nov 14 00:14 /lib/libdl-2.16.so&lt;br /&gt;
 -rw-r--r--    1 root     root         19398 Nov 14 00:45 /etc/services&lt;br /&gt;
 -rwxr-xr-x    1 root     root         22020 Nov 14 00:14 /lib/libnss_dns-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root         26064 Nov 14 00:14 /lib/libcrypt-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root         30624 Nov 14 00:14 /lib/librt-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root         34588 Nov 14 00:14 /lib/libnss_compat-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root         46980 Nov 14 00:14 /lib/libnss_files-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root         83716 Nov 14 00:14 /lib/libresolv-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root         87860 Nov 14 00:14 /lib/libnsl-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root         96128 Nov 14 00:14 /lib/libpthread-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root        127228 Nov 14 00:14 /lib/ld-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root        251328 Nov 14 00:14 /lib/libm-2.16.so&lt;br /&gt;
 -rwxr-xr-x    1 root     root        524924 Nov 14 00:14 /sbin/ldconfig&lt;br /&gt;
 -rwsr-xr-x    1 root     root        554820 Nov 14 00:22 /bin/busybox&lt;br /&gt;
 -rwxr-xr-x    1 root     root       1056128 Nov 14 00:14 /lib/libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
busybox, ldconfig and libc (and other libc-related libs) make up about 95% of the system.&lt;br /&gt;
&lt;br /&gt;
If busybox were statically linked, and ldconfig and libc were omitted, I believe it would&lt;br /&gt;
reduce the size of the system substantially.&lt;br /&gt;
&lt;br /&gt;
=== exiting the system ===&lt;br /&gt;
There is no &#039;shutdown&#039; command, but you can use &#039;ctrl-a to execute a command to the qemu monitor, and &#039;ctrl-a b&#039; to issue a sysrq to the Linux kernel.&lt;br /&gt;
You can do a sysrq-B to do a reboot.  Do: ctrl-a h to see available commands, and ctrl-a x to exit qemu.&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
* Presentation: [http://elinux.org/images/2/2b/Elce11_hart.pdf Tuning Linux For Embedded Systems: When Less Is More] by Darren Hart, ELC Europe 2011, October 2011, Prague, Czech Republic&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19235</id>
		<title>TipsAndTricks/DemystifyingTheLinuxYoctoKernel</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19235"/>
		<updated>2016-06-27T20:54:03Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Despite the existence of plenty of in-depth documentation out there on working with kernels in Yocto, most people seem to still view the subject as &#039;a riddle, wrapped in a mystery, inside an enigma&#039;.  [1][2]&lt;br /&gt;
&lt;br /&gt;
This is the first in what should be a short series of articles dealing with Yocto kernels, focusing only on the bare essentials.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s start first with the kernel itself.  When most people think of a kernel in Yocto, they tend to think of it as something that&#039;s wrapped inside a kernel recipe, which in turn is something that&#039;s wrapped inside the build system and generated into the final image.  That&#039;s all true and valid, but all those extra layers (let&#039;s call them the mystery and the enigma for now) obscure the kernel of truth at the center (the riddle).  Let&#039;s just look at the riddle and come back some other day to explain the mystery and the enigma.&lt;br /&gt;
&lt;br /&gt;
At its heart, a Yocto kernel is just exactly the same thing as an upstream Linux kernel.&lt;br /&gt;
&lt;br /&gt;
To make that point clear, let&#039;s take a quick look at a typical kernel development workflow outside of Yocto (don&#039;t let the phrase &#039;kernel development workflow&#039; scare you off - for the purposes of this article it just refers to compiling and building and possibly configuring a kernel, which is something anyone dealing with a build system like Yocto should be comfortable with).&lt;br /&gt;
&lt;br /&gt;
To modify code, configure, build, and boot a new kernel outside of Yocto, you&#039;d typically do something like this [3]:&lt;br /&gt;
&lt;br /&gt;
 $ edit the kernel source (or don&#039;t if you&#039;re just configuring or building)&lt;br /&gt;
 $ make menuconfig&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 select/deselect new config items&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 $ make bzImage&lt;br /&gt;
 $ scp arch/x86/boot/bzImage 10.0.0.18/mnt/bzImage&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 reboot target and see changes&lt;br /&gt;
&lt;br /&gt;
The same thing in Yocto would be:&lt;br /&gt;
&lt;br /&gt;
 $ edit the kernel source (or don&#039;t if you&#039;re just configuring or building) [4]&lt;br /&gt;
 $ bitbake -c menuconfig virtual/kernel&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 select/deselect new config items&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 $ bitbake -c compile -f virtual/kernel&lt;br /&gt;
 $ scp tmp/work/core2-32-intel-common-poky-linux/linux-yocto/4.1.26+gitAUTOINC+9f68667031_9195020e57-r0/linux-core2-32-intel-common-standard-build/arch/x86/boot/bzImage 10.0.0.18:/mnt/bzImage&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 reboot target and see changes&lt;br /&gt;
&lt;br /&gt;
As you can see, the only differences in the Yocto version are trivial: in Yocto, you use &#039;bitbake&#039; instead of &#039;make&#039;, and in Yocto, you have to deal with a godawful long and ugly path to the final kernel image. [5]&lt;br /&gt;
&lt;br /&gt;
Even though it&#039;s very similar at its barest level, the Yocto version gives you one thing that the non-Yocto version doesn&#039;t - the ability to cross-compile for a different target, which is automatically hidden beneath the &#039;bitbake&#039; command.  In this example, we may happen to be building on the same type of host as we are targeting, for example, x86-64, but with the Yocto/bitbake version, we could build for any target and it would use essentially the same procedure.&lt;br /&gt;
&lt;br /&gt;
Of course, this says nothing about saving your changes and allowing other users to access them, which is basically what the rest of the build system is all about, and which for now is a mystery we&#039;ll cover in a future article.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[1] [https://www.yoctoproject.org/training/kernel-lab Yocto kernel labs]&lt;br /&gt;
&lt;br /&gt;
[2] [http://www.yoctoproject.org/docs/2.1/kernel-dev/kernel-dev.html Yocto Kernel Development Manual]&lt;br /&gt;
&lt;br /&gt;
[3] This assumes that the target is network-connected and you&#039;ve mounted the boot partition at /mnt on the target, e.g.:&lt;br /&gt;
 $ mount /dev/mmcblk0p1 /mnt&lt;br /&gt;
&lt;br /&gt;
[4] In the Yocto version, the source you&#039;d modify is located at something like tmp/work/core2-32-intel-common-poky-linux/linux-yocto/4.1.26+gitAUTOINC+9f68667031_9195020e57-r0/linux-core2-32-intel-common-standard-build/source/ (see [5] for context)&lt;br /&gt;
&lt;br /&gt;
[5] This is nothing mysterious either.  Just start at the build directory and follow the path to the kernel like so (this is just a typical example - there normally aren&#039;t many ways to get lost, making it look worse than it is):&lt;br /&gt;
 $ cd tmp&lt;br /&gt;
 $ cd work&lt;br /&gt;
 $ cd core2-32-intel-common-poky-linux&lt;br /&gt;
 $ cd linux-yocto&lt;br /&gt;
 $ cd 4.1.26+gitAUTOINC+9f68667031_9195020e57-r0&lt;br /&gt;
 $ cd linux-core2-32-intel-common-standard-build&lt;br /&gt;
 $ scp arch/x86/boot/bzImage target:/mnt/bzImage&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19234</id>
		<title>TipsAndTricks/DemystifyingTheLinuxYoctoKernel</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19234"/>
		<updated>2016-06-27T20:40:56Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Despite the existence of plenty of in-depth documentation out there on working with kernels in Yocto, most people seem to still view the subject as &#039;a riddle, wrapped in a mystery, inside an enigma&#039;.  [1][2]&lt;br /&gt;
&lt;br /&gt;
This is the first in what should be a short series of articles dealing with Yocto kernels, focusing only on the bare essentials.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s start first with the kernel itself.  When most people think of a kernel in Yocto, they tend to think of it as something that&#039;s wrapped inside a kernel recipe, which in turn is something that&#039;s wrapped inside the build system and generated into the final image.  That&#039;s all true and valid, but all those extra layers (let&#039;s call them the mystery and the enigma for now) obscure the kernel of truth at the center (the riddle).  Let&#039;s just look at the riddle and come back some other day to explain the mystery and the enigma.&lt;br /&gt;
&lt;br /&gt;
At its heart, a Yocto kernel is just exactly the same thing as an upstream Linux kernel.&lt;br /&gt;
&lt;br /&gt;
To make that point clear, let&#039;s take a quick look at a typical kernel development workflow outside of Yocto (don&#039;t let the phrase &#039;kernel development workflow&#039; scare you off - for the purposes of this article it just refers to compiling and building and possibly configuring a kernel, which is something anyone dealing with a build system like Yocto should be comfortable with).&lt;br /&gt;
&lt;br /&gt;
To configure, build, and boot a new kernel outside of Yocto, you&#039;d typically do something like this[3]:&lt;br /&gt;
&lt;br /&gt;
 $ make menuconfig&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 select/deselect new config items&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 $ make bzImage&lt;br /&gt;
 $ scp arch/x86/boot/bzImage 10.0.0.18/mnt/bzImage&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 reboot target and see changes&lt;br /&gt;
&lt;br /&gt;
The same thing in Yocto would be:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake -c menuconfig virtual/kernel&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 select/deselect new config items&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 $ bitbake -c compile -f virtual/kernel&lt;br /&gt;
 $ scp tmp/work/core2-32-intel-common-poky-linux/linux-yocto/4.1.26+gitAUTOINC+9f68667031_9195020e57-r0/linux-core2-32-intel-common-standard-build/arch/x86/boot/bzImage 10.0.0.18:/mnt/bzImage&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 reboot target and see changes&lt;br /&gt;
&lt;br /&gt;
As you can see, the only differences in the Yocto version are trivial: in Yocto, you use &#039;bitbake&#039; instead of &#039;make&#039;, and in Yocto, you have to deal with a godawful long and ugly path to the final kernel image. [4]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[1] [https://www.yoctoproject.org/training/kernel-lab Yocto kernel labs]&lt;br /&gt;
&lt;br /&gt;
[2] [http://www.yoctoproject.org/docs/2.1/kernel-dev/kernel-dev.html Yocto Kernel Development Manual]&lt;br /&gt;
&lt;br /&gt;
[3] This assumes that the target is network-connected and you&#039;ve mounted the boot partition at /mnt on the target, e.g.:&lt;br /&gt;
 $ mount /dev/mmcblk0p1 /mnt&lt;br /&gt;
&lt;br /&gt;
[4] This is nothing mysterious either.  Just start at the build directory and follow the path to the kernel like so (this is just a typical example - there normally aren&#039;t many ways to get lost, making it look worse than it is):&lt;br /&gt;
 $ cd tmp&lt;br /&gt;
 $ cd work&lt;br /&gt;
 $ cd core2-32-intel-common-poky-linux&lt;br /&gt;
 $ cd linux-yocto&lt;br /&gt;
 $ cd 4.1.26+gitAUTOINC+9f68667031_9195020e57-r0&lt;br /&gt;
 $ cd linux-core2-32-intel-common-standard-build&lt;br /&gt;
 $ scp arch/x86/boot/bzImage target:/mnt/bzImage&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19233</id>
		<title>TipsAndTricks/DemystifyingTheLinuxYoctoKernel</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19233"/>
		<updated>2016-06-27T20:37:59Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Despite the existence of plenty of in-depth documentation out there on working with kernels in Yocto, most people seem to still view the subject as &#039;a riddle, wrapped in a mystery, inside an enigma&#039;.  [1][2]&lt;br /&gt;
&lt;br /&gt;
This is the first in what should be a short series of articles dealing with Yocto kernels, focusing only on the bare essentials.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s start first with the kernel itself.  When most people think of a kernel in Yocto, they tend to think of it as something that&#039;s wrapped inside a kernel recipe, which in turn is something that&#039;s wrapped inside the build system and generated into the final image.  That&#039;s all true and valid, but all those extra layers (let&#039;s call them the mystery and the enigma for now) obscure the kernel of truth at the center (the riddle).  Let&#039;s just look at the riddle and come back some other day to explain the mystery and the enigma.&lt;br /&gt;
&lt;br /&gt;
At its heart, a Yocto kernel is just exactly the same thing as an upstream Linux kernel.&lt;br /&gt;
&lt;br /&gt;
To make that point clear, let&#039;s take a quick look at a typical kernel development workflow outside of Yocto (don&#039;t let the phrase &#039;kernel development workflow&#039; scare you off - for the purposes of this article it just refers to compiling and building and possibly configuring a kernel, which is something anyone dealing with a build system like Yocto should be comfortable with).&lt;br /&gt;
&lt;br /&gt;
To configure, build, and boot a new kernel outside of Yocto, you&#039;d typically do something like this:&lt;br /&gt;
&lt;br /&gt;
 $ make menuconfig&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 select/deselect new config items&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 $ make bzImage&lt;br /&gt;
 $ scp arch/x86/boot/bzImage 10.0.0.18/mnt/bzImage&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 reboot target and see changes&lt;br /&gt;
&lt;br /&gt;
The same thing in Yocto would be:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake -c menuconfig virtual/kernel&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 select/deselect new config items&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 $ bitbake -c compile -f virtual/kernel&lt;br /&gt;
 $ scp tmp/work/core2-32-intel-common-poky-linux/linux-yocto/4.1.26+gitAUTOINC+9f68667031_9195020e57-r0/linux-core2-32-intel-common-standard-build/arch/x86/boot/bzImage 10.0.0.18:/mnt/bzImage&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 reboot target and see changes&lt;br /&gt;
&lt;br /&gt;
As you can see, the only differences in the Yocto version are trivial: in Yocto, you use &#039;bitbake&#039; instead of &#039;make&#039;, and in Yocto, you have to deal with a godawful long and ugly path to the final kernel image. [3]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[1] [https://www.yoctoproject.org/training/kernel-lab Yocto kernel labs]&lt;br /&gt;
&lt;br /&gt;
[2] [http://www.yoctoproject.org/docs/2.1/kernel-dev/kernel-dev.html Yocto Kernel Development Manual]&lt;br /&gt;
&lt;br /&gt;
[3] This is nothing mysterious either.  Just start at the build directory and follow the path to the kernel like so (this is just a typical example - there normally aren&#039;t many ways to get lost, making it look worse than it is):&lt;br /&gt;
 $ cd tmp&lt;br /&gt;
 $ cd work&lt;br /&gt;
 $ cd core2-32-intel-common-poky-linux&lt;br /&gt;
 $ cd linux-yocto&lt;br /&gt;
 $ cd 4.1.26+gitAUTOINC+9f68667031_9195020e57-r0&lt;br /&gt;
 $ cd linux-core2-32-intel-common-standard-build&lt;br /&gt;
 $ scp arch/x86/boot/bzImage target:/mnt/bzImage&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19232</id>
		<title>TipsAndTricks/DemystifyingTheLinuxYoctoKernel</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19232"/>
		<updated>2016-06-27T20:21:58Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Despite the existence of plenty of in-depth documentation out there on working with kernels in Yocto, most people seem to still view the subject as &#039;a riddle, wrapped in a mystery, inside an enigma&#039;.  [1][2]&lt;br /&gt;
&lt;br /&gt;
This is the first in what should be a short series of articles dealing with Yocto kernels, focusing only on the bare essentials.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s start first with the kernel itself.  When most people think of a kernel in Yocto, they tend to think of it as something that&#039;s wrapped inside a kernel recipe, which in turn is something that&#039;s wrapped inside the build system and generated into the final image.  That&#039;s all true and valid, but all those extra layers (let&#039;s call them the mystery and the enigma for now) obscure the kernel of truth at the center (the riddle).  Let&#039;s just look at the riddle and come back some other day to explain the mystery and the enigma.&lt;br /&gt;
&lt;br /&gt;
At its heart, a Yocto kernel is just exactly the same thing as an upstream Linux kernel.&lt;br /&gt;
&lt;br /&gt;
To make that point clear, let&#039;s take a quick look at a typical kernel development workflow outside of Yocto (don&#039;t let the phrase &#039;kernel development workflow&#039; scare you off - for the purposes of this article it just refers to compiling and building and possibly configuring a kernel, which is something anyone dealing with a build system like Yocto should be comfortable with).&lt;br /&gt;
&lt;br /&gt;
To configure, build, and boot a new kernel outside of Yocto, you&#039;d typically do something like this:&lt;br /&gt;
&lt;br /&gt;
 $ make menuconfig&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 select/deselect new config items&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 $ make bzImage&lt;br /&gt;
 $ scp arch/x86/boot/bzImage 10.0.0.18/mnt/bzImage&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 reboot target and see changes&lt;br /&gt;
&lt;br /&gt;
The same thing in Yocto would be:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake -c menuconfig virtual/kernel&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 select/deselect new config items&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 $ bitbake -c compile -f virtual/kernel&lt;br /&gt;
 $ scp tmp/work/core2-32-intel-common-poky-linux/linux-yocto/4.1.26+gitAUTOINC+9f68667031_9195020e57-r0/linux-core2-32-intel-common-standard-build/arch/x86/boot/bzImage 10.0.0.18:/mnt/bzImage&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 reboot target and see changes&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[1] [https://www.yoctoproject.org/training/kernel-lab Yocto kernel labs]&lt;br /&gt;
&lt;br /&gt;
[2] [http://www.yoctoproject.org/docs/2.1/kernel-dev/kernel-dev.html Yocto Kernel Development Manual]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19231</id>
		<title>TipsAndTricks/DemystifyingTheLinuxYoctoKernel</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19231"/>
		<updated>2016-06-27T20:08:18Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Despite the existence of plenty of in-depth documentation out there on working with kernels in Yocto, most people seem to still view the subject as &#039;a riddle, wrapped in a mystery, inside an enigma&#039;.  [1][2]&lt;br /&gt;
&lt;br /&gt;
This is the first in what should be a short series of articles dealing with Yocto kernels, focusing only on the bare essentials.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s start first with the kernel itself.  When most people think of a kernel in Yocto, they tend to think of it as something that&#039;s wrapped inside a kernel recipe, which in turn is something that&#039;s wrapped inside the build system and generated into the final image.  That&#039;s all true and valid, but all those extra layers (let&#039;s call them the mystery and the enigma for now) obscure the kernel of truth at the center (the riddle).  Let&#039;s just look at the riddle and come back some other day to explain the mystery and the enigma.&lt;br /&gt;
&lt;br /&gt;
At its heart, a Yocto kernel is just exactly the same thing as an upstream Linux kernel.&lt;br /&gt;
&lt;br /&gt;
To make that point clear, let&#039;s take a quick look at a typical kernel development workflow outside of Yocto (don&#039;t let the phrase &#039;kernel development workflow&#039; scare you off - for the purposes of this article it just refers to compiling and building and possibly configuring a kernel, which is something anyone dealing with a build system like Yocto should be comfortable with).&lt;br /&gt;
&lt;br /&gt;
To configure, build, and boot a new kernel outside of Yocto, you&#039;d typically do something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[1] [https://www.yoctoproject.org/training/kernel-lab Yocto kernel labs]&lt;br /&gt;
&lt;br /&gt;
[2] [http://www.yoctoproject.org/docs/2.1/kernel-dev/kernel-dev.html Yocto Kernel Development Manual]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19230</id>
		<title>TipsAndTricks/DemystifyingTheLinuxYoctoKernel</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19230"/>
		<updated>2016-06-27T19:52:58Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Despite the existence of plenty of in-depth documentation out there on working with kernels in Yocto, most people seem to still view the subject as &#039;a riddle, wrapped in a mystery, inside an enigma&#039;.  [1][2]&lt;br /&gt;
&lt;br /&gt;
This is the first in what should be a short series of articles dealing with Yocto kernels, focusing only on the bare essentials.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s start first with the kernel itself.  When most people think of a kernel in Yocto, they tend to think of it as something that&#039;s wrapped inside a kernel recipe, which in turn is something that&#039;s wrapped inside the build system and generated into the final image.  That&#039;s all true and valid, but all those extra layers (let&#039;s call them the mystery and the enigma for now) obscure the kernel of truth at the center (the riddle).  Let&#039;s just look at the riddle and come back some other day to explain the mystery and the enigma.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[1] [https://www.yoctoproject.org/training/kernel-lab Yocto kernel labs]&lt;br /&gt;
&lt;br /&gt;
[2] [http://www.yoctoproject.org/docs/2.1/kernel-dev/kernel-dev.html Yocto Kernel Development Manual]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19229</id>
		<title>TipsAndTricks/DemystifyingTheLinuxYoctoKernel</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks/DemystifyingTheLinuxYoctoKernel&amp;diff=19229"/>
		<updated>2016-06-27T19:43:10Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: Created page with &amp;quot;Despite the existence of plenty of in-depth documentation out there on working with kernels in Yocto, most people seem to still view the subject as a riddle wrapped in a myste...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Despite the existence of plenty of in-depth documentation out there on working with kernels in Yocto, most people seem to still view the subject as a riddle wrapped in a mystery inside an enigma [1][2].&lt;br /&gt;
&lt;br /&gt;
This is the first in what should be a short series of articles dealing with Yocto kernels, focusing only on the bare essentials.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[1] [https://www.yoctoproject.org/training/kernel-lab Yocto kernel labs]&lt;br /&gt;
&lt;br /&gt;
[2] [http://www.yoctoproject.org/docs/2.1/kernel-dev/kernel-dev.html Yocto Kernel Development Manual]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks&amp;diff=19228</id>
		<title>TipsAndTricks</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=TipsAndTricks&amp;diff=19228"/>
		<updated>2016-06-27T19:31:12Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Articles in development ==&lt;br /&gt;
&lt;br /&gt;
* [[TipsAndTricks/DebugNativeRecipeWithGdb]] (Joshua Lock)&lt;br /&gt;
* [[TipsAndTricks/Netconsole]] (Ross Burton)&lt;br /&gt;
* [[TipsAndTricks/ParsingProfiling]] (Richard Purdie)&lt;br /&gt;
* [[TipsAndTricks/NPM]] (Brendan)&lt;br /&gt;
* [[TipsAndTricks/DemystifyingTheLinuxYoctoKernel]] (Tom Zanussi)&lt;br /&gt;
&lt;br /&gt;
== Articles ready for publishing ==&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9763</id>
		<title>Meta-intel Release Process</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9763"/>
		<updated>2013-04-23T18:53:34Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;meta-intel releases happen with the same cadence that poky releases happen, though the actual release may be staggered with respect to the associated poky release.  We now attempt to co-release with poky, or at least have everything ready to co-release, but the actual release decision may dictate that we don&#039;t actually co-release.  The meta-intel release may also be staggered simply because meta-intel needs the extra time to stabilize against the associated poky release.&lt;br /&gt;
&lt;br /&gt;
This pages attempts to capture the meta-intel release process as it exists - it isn&#039;t meant to be an official or binding document.&lt;br /&gt;
&lt;br /&gt;
Also, this process only addresses the BSPs built and released by the Yocto Autobuilder team, and tested by the Yocto QA team - it doesn&#039;t address the release process for any BSPs that are managed outside of that process, such as the ISG BSPs, which may be built using a separate autobuilder and tested by ISG, i.e. which have their own release process, though their metadata may exist within the meta-intel and linux-yocto repositories.&lt;br /&gt;
&lt;br /&gt;
=== Overall Responsibilities ===&lt;br /&gt;
&lt;br /&gt;
The meta-intel repository consists of a set of BSPs and some common metadata.  Because those BSPs each have separate owners, we can&#039;t make a blanket assertion that all those BSPs will be released as part of a meta-intel release.  It would be nice to be able to do so, but in reality, different groups of maintainers may decide to do separate releases.  As such. this section only describes the perceived responsibilities of the maintainers for the set of BSPs controlled by the Yocto team.&lt;br /&gt;
&lt;br /&gt;
The Yocto Project Program Manager has the ultimate responsibility for coordinating the various BSP owners and managing the overall meta-intel release.&lt;br /&gt;
&lt;br /&gt;
* Basically the BSP maintainer(s) are responsible for tracking the release milestones and making sure the BSPs are up-to-date and releasable with respect to the poky release.  This includes all recipe upgrades and bugfixes intended to go into the release.&lt;br /&gt;
* At each release candidate, the autobuilder team generates the images passes them on to QA for testing.&lt;br /&gt;
* QA tests and provides feedback on how the BSPs meet the release criteria.&lt;br /&gt;
* The BSP maintainer(s) fix any problems found by QA, and the cycle repeats itself in the next RC cycle, until all BSPs can be released.&lt;br /&gt;
&lt;br /&gt;
Once the BSPs are ready to be released from the BSP maintainer&#039;s and QA team standpoint, the autobuilder team generates release tarballs for each BSP and makes them available to the Yocto website maintainers for availability as downloads on the Yocto website.&lt;br /&gt;
* The yocto website maintainers make the tarballs available from pages containing the release notes for each BSP, along with test reports and image verification status for each (see sections below for details).&lt;br /&gt;
* Any problems not fixed by the BSP maintainers need to be noted by the maintainer and sent to the website maintainer and Yocto documentation maintainer as &#039;Layer-specific Notes&#039; to be appended to each affected BSP&#039;s release notes (see below).&lt;br /&gt;
&lt;br /&gt;
=== Branch and Tag Management ===&lt;br /&gt;
&lt;br /&gt;
The autobuilder maintainers are the only ones who can create new branches and release tags in meta-intel, and will do so when necessary as required to generate the infrastructure needed for a release.&lt;br /&gt;
* Once a new branch is created for the release, the meta-intel maintainer(s) will add new commits to both master and the release branch up until the time of release (as appropriate - some patches may only be intended for master or the release)&lt;br /&gt;
&lt;br /&gt;
=== Release Notes ===&lt;br /&gt;
&lt;br /&gt;
Currently, the &#039;release notes&#039; for a BSP consist of the information found on the web page for the BSP in the &#039;Downloads&#039; section for the BSP, and essentially consists of the BSP&#039;s README along with a &#039;Layer-Specific Notes&#039; section, which is tacked on to the end of the page.&lt;br /&gt;
&lt;br /&gt;
* The Yocto documentation and website maintainers will be responsible for the content of the BSP pages and will ask the BSP maintainer(s) for any additional information needed for a particular BSP&lt;br /&gt;
* Normally the only thing needed from the BSP maintainer(s) are the &#039;Layer-Specific Notes&#039; for a BSP, which the BSP maintainers should supply to the documentation and website maintainers unsolicited as part of the release process.&lt;br /&gt;
** Any layer-specific notes that affect multiple or all BSPs should be attached to each BSP separately in the &#039;Layer-Specific Notes&#039; section.&lt;br /&gt;
* The title used for the BSP on the website is retrieved by the documentation and website maintainers from the BSP&#039;s WEBTITLE field in the BSP&#039;s machine.conf, and should therefore reflect accurately how the BSP is identified on the website.  This may be a string defined by marketing, and should at least be approved by marketing.&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
According to the Yocto Project compliance requirements, no meta-intel BSP can be released without testing data.  The webpage for each BSP must contain a link to the testing data generated for every image contained in a released BSP.  For the BSPs tested by Yocto QA, the QA test report should be the one linked to for those BSPs.&lt;br /&gt;
&lt;br /&gt;
=== Image Verification ===&lt;br /&gt;
&lt;br /&gt;
For every BSP image contained in a tarball released on the Yocto website, it must be verified that the image can be independently generated from scratch (including downloads) using the released metadata.&lt;br /&gt;
&lt;br /&gt;
Customers must (and have, and will) be able to verify that the images contained in the release tarball can in fact be generated from the combination of the metadata contained in the BSP tarball and the set of packages downloaded by the build (from a scratch build) process to create those images. &lt;br /&gt;
&lt;br /&gt;
In practice, this means that the autobuilder maintainer needs to supply the settings required to generate the BSP to the person verifiying the image.  If the release tarball is generated by some other process, the BSP maintainer needs to supply that information.&lt;br /&gt;
* Note that all images released on the website must contain a time-limited kernel and this must be taken into account when verifying the image.&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9762</id>
		<title>Meta-intel Release Process</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9762"/>
		<updated>2013-04-23T18:50:34Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;meta-intel releases happen with the same cadence that poky releases happen, though the actual release may be staggered with respect to the associated poky release.  We now attempt to co-release with poky, or at least have everything ready to co-release, but the actual release decision may dictate that we don&#039;t actually co-release.  The meta-intel release may also be staggered simply because meta-intel needs the extra time to stabilize against the associated poky release.&lt;br /&gt;
&lt;br /&gt;
This pages attempts to capture the meta-intel release process as it exists - it isn&#039;t meant to be an official or binding document.&lt;br /&gt;
&lt;br /&gt;
Also, this process only addresses the BSPs built and released by the Yocto Autobuilder team, and tested by the Yocto QA team - it doesn&#039;t address the release process for any BSPs that are managed outside of that process, such as the ISG BSPs, which may be built using a separate autobuilder and tested by ISG, i.e. which have their own release process, though their metadata may exist within the meta-intel and linux-yocto repositories.&lt;br /&gt;
&lt;br /&gt;
=== Overall Responsibilities ===&lt;br /&gt;
&lt;br /&gt;
The meta-intel repository consists of a set of BSPs and some common metadata.  Because those BSPs each have separate owners, we can&#039;t make a blanket assertion that all those BSPs will be released as part of a meta-intel release.  It would be nice to be able to do so, but in reality, different groups of maintainers may decide to do separate releases.  As such. this section only describes the perceived responsibilities of the maintainers for the set of BSPs controlled by the Yocto team.&lt;br /&gt;
&lt;br /&gt;
* Basically the BSP maintainer(s) are responsible for tracking the release milestones and making sure the BSPs are up-to-date and releasable with respect to the poky release.  This includes all recipe upgrades and bugfixes intended to go into the release.&lt;br /&gt;
* At each release candidate, the autobuilder team generates the images passes them on to QA for testing.&lt;br /&gt;
* QA tests and provides feedback on how the BSPs meet the release criteria.&lt;br /&gt;
* The BSP maintainer(s) fix any problems found by QA, and the cycle repeats itself in the next RC cycle, until all BSPs can be released.&lt;br /&gt;
&lt;br /&gt;
Once the BSPs are ready to be released from the BSP maintainer&#039;s and QA team standpoint, the autobuilder team generates release tarballs for each BSP and makes them available to the Yocto website maintainers for availability as downloads on the Yocto website.&lt;br /&gt;
* The yocto website maintainers make the tarballs available from pages containing the release notes for each BSP, along with test reports and image verification status for each (see sections below for details).&lt;br /&gt;
* Any problems not fixed by the BSP maintainers need to be noted by the maintainer and sent to the website maintainer and Yocto documentation maintainer as &#039;Layer-specific Notes&#039; to be appended to each affected BSP&#039;s release notes (see below).&lt;br /&gt;
&lt;br /&gt;
=== Branch and Tag Management ===&lt;br /&gt;
&lt;br /&gt;
The autobuilder maintainers are the only ones who can create new branches and release tags in meta-intel, and will do so when necessary as required to generate the infrastructure needed for a release.&lt;br /&gt;
* Once a new branch is created for the release, the meta-intel maintainer(s) will add new commits to both master and the release branch up until the time of release (as appropriate - some patches may only be intended for master or the release)&lt;br /&gt;
&lt;br /&gt;
=== Release Notes ===&lt;br /&gt;
&lt;br /&gt;
Currently, the &#039;release notes&#039; for a BSP consist of the information found on the web page for the BSP in the &#039;Downloads&#039; section for the BSP, and essentially consists of the BSP&#039;s README along with a &#039;Layer-Specific Notes&#039; section, which is tacked on to the end of the page.&lt;br /&gt;
&lt;br /&gt;
* The Yocto documentation and website maintainers will be responsible for the content of the BSP pages and will ask the BSP maintainer(s) for any additional information needed for a particular BSP&lt;br /&gt;
* Normally the only thing needed from the BSP maintainer(s) are the &#039;Layer-Specific Notes&#039; for a BSP, which the BSP maintainers should supply to the documentation and website maintainers unsolicited as part of the release process.&lt;br /&gt;
** Any layer-specific notes that affect multiple or all BSPs should be attached to each BSP separately in the &#039;Layer-Specific Notes&#039; section.&lt;br /&gt;
* The title used for the BSP on the website is retrieved by the documentation and website maintainers from the BSP&#039;s WEBTITLE field in the BSP&#039;s machine.conf, and should therefore reflect accurately how the BSP is identified on the website.  This may be a string defined by marketing, and should at least be approved by marketing.&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
According to the Yocto Project compliance requirements, no meta-intel BSP can be released without testing data.  The webpage for each BSP must contain a link to the testing data generated for every image contained in a released BSP.  For the BSPs tested by Yocto QA, the QA test report should be the one linked to for those BSPs.&lt;br /&gt;
&lt;br /&gt;
=== Image Verification ===&lt;br /&gt;
&lt;br /&gt;
For every BSP image contained in a tarball released on the Yocto website, it must be verified that the image can be independently generated from scratch (including downloads) using the released metadata.&lt;br /&gt;
&lt;br /&gt;
Customers must (and have, and will) be able to verify that the images contained in the release tarball can in fact be generated from the combination of the metadata contained in the BSP tarball and the set of packages downloaded by the build (from a scratch build) process to create those images. &lt;br /&gt;
&lt;br /&gt;
In practice, this means that the autobuilder maintainer needs to supply the settings required to generate the BSP to the person verifiying the image.  If the release tarball is generated by some other process, the BSP maintainer needs to supply that information.&lt;br /&gt;
* Note that all images released on the website must contain a time-limited kernel and this must be taken into account when verifying the image.&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9761</id>
		<title>Meta-intel Release Process</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9761"/>
		<updated>2013-04-23T17:22:08Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;meta-intel releases happen with the same cadence that poky releases happen, though the actual release may be staggered with respect to the associated poky release.  We now attempt to co-release with poky, or at least have everything ready to co-release, but the actual release decision may dictate that we don&#039;t actually co-release.  The meta-intel release may also be staggered simply because meta-intel needs the extra time to stabilize against the associated poky release.&lt;br /&gt;
&lt;br /&gt;
This pages attempts to capture the meta-intel release process as it exists - it isn&#039;t meant to be an official or binding document.&lt;br /&gt;
&lt;br /&gt;
Also, this process only addresses the BSPs built and released by the Yocto Autobuilder team, and tested by the Yocto QA team - it doesn&#039;t address the release process for any BSPs that are managed outside of that process, such as the ISG BSPs, which may be built using a separate autobuilder and tested by ISG, i.e. which have their own release process, though their metadata may exist within the meta-intel and linux-yocto repositories.&lt;br /&gt;
&lt;br /&gt;
=== Branch and Tag Management ===&lt;br /&gt;
&lt;br /&gt;
The autobuilder maintainers are the only ones who can create new branches and release tags in meta-intel, and will do so when necessary as required to generate the infrastructure needed for a release.&lt;br /&gt;
* Once a new branch is created for the release, the meta-intel maintainer(s) will add new commits to both master and the release branch up until the time of release (as appropriate - some patches may only be intended for master or the release)&lt;br /&gt;
&lt;br /&gt;
=== Release Notes ===&lt;br /&gt;
&lt;br /&gt;
Currently, the &#039;release notes&#039; for a BSP consist of the information found on the web page for the BSP in the &#039;Downloads&#039; section for the BSP, and essentially consists of the BSP&#039;s README along with a &#039;Layer-Specific Notes&#039; section, which is tacked on to the end of the page.&lt;br /&gt;
&lt;br /&gt;
* The Yocto documentation and website maintainers will be responsible for the content of the BSP pages and will ask the BSP maintainer(s) for any additional information needed for a particular BSP&lt;br /&gt;
* Normally the only thing needed from the BSP maintainer(s) are the &#039;Layer-Specific Notes&#039; for a BSP, which the BSP maintainers should supply to the documentation and website maintainers unsolicited as part of the release process.&lt;br /&gt;
** Any layer-specific notes that affect multiple or all BSPs should be attached to each BSP separately in the &#039;Layer-Specific Notes&#039; section.&lt;br /&gt;
* The title used for the BSP on the website is retrieved by the documentation and website maintainers from the BSP&#039;s WEBTITLE field in the BSP&#039;s machine.conf, and should therefore reflect accurately how the BSP is identified on the website.  This may be a string defined by marketing, and should at least be approved by marketing.&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
According to the Yocto Project compliance requirements, no meta-intel BSP can be released without testing data.  The webpage for each BSP must contain a link to the testing data generated for every image contained in a released BSP.  For the BSPs tested by Yocto QA, the QA test report should be the one linked to for those BSPs.&lt;br /&gt;
&lt;br /&gt;
=== Image Verification ===&lt;br /&gt;
&lt;br /&gt;
For every BSP image contained in a tarball released on the Yocto website, it must be verified that the image can be independently generated from scratch (including downloads) using the released metadata.&lt;br /&gt;
&lt;br /&gt;
Customers must (and have, and will) be able to verify that the images contained in the release tarball can in fact be generated from the combination of the metadata contained in the BSP tarball and the set of packages downloaded by the build (from a scratch build) process to create those images. &lt;br /&gt;
&lt;br /&gt;
In practice, this means that the autobuilder maintainer needs to supply the settings required to generate the BSP to the person verifiying the image.  If the release tarball is generated by some other process, the BSP maintainer needs to supply that information.&lt;br /&gt;
* Note that all images released on the website must contain a time-limited kernel and this must be taken into account when verifying the image.&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9760</id>
		<title>Meta-intel Release Process</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9760"/>
		<updated>2013-04-23T17:16:50Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Image Verification */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;meta-intel releases happen with the same cadence that poky releases happen, though the actual release may be staggered with respect to the associated poky release.  We now attempt to co-release with poky, or at least have everything ready to co-release, but the actual release decision may dictate that we don&#039;t actually co-release.  The meta-intel release may also be staggered simply because meta-intel needs the extra time to stabilize against the associated poky release.&lt;br /&gt;
&lt;br /&gt;
This pages attempts to capture the meta-intel release process as it exists - it isn&#039;t meant to be an official or binding document.&lt;br /&gt;
&lt;br /&gt;
Also, this process only addresses the BSPs built and released by the Yocto Autobuilder team, and tested by the Yocto QA team - it doesn&#039;t address the release process for any BSPs that are managed outside of that process, such as the ISG BSPs, which may be built using a separate autobuilder and tested by ISG, i.e. which have their own release process, though their metadata may exist within the meta-intel and linux-yocto repositories.&lt;br /&gt;
&lt;br /&gt;
=== Release Notes ===&lt;br /&gt;
&lt;br /&gt;
Currently, the &#039;release notes&#039; for a BSP consist of the information found on the web page for the BSP in the &#039;Downloads&#039; section for the BSP, and essentially consists of the BSP&#039;s README along with a &#039;Layer-Specific Notes&#039; section, which is tacked on to the end of the page.&lt;br /&gt;
&lt;br /&gt;
* The Yocto documentation and website maintainers will be responsible for the content of the BSP pages and will ask the BSP maintainer(s) for any additional information needed for a particular BSP&lt;br /&gt;
* Normally the only thing needed from the BSP maintainer(s) are the &#039;Layer-Specific Notes&#039; for a BSP, which the BSP maintainers should supply to the documentation and website maintainers unsolicited as part of the release process.&lt;br /&gt;
** Any layer-specific notes that affect multiple or all BSPs should be attached to each BSP separately in the &#039;Layer-Specific Notes&#039; section.&lt;br /&gt;
* The title used for the BSP on the website is retrieved by the documentation and website maintainers from the BSP&#039;s WEBTITLE field in the BSP&#039;s machine.conf, and should therefore reflect accurately how the BSP is identified on the website.  This may be a string defined by marketing, and should at least be approved by marketing.&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
According to the Yocto Project compliance requirements, no meta-intel BSP can be released without testing data.  The webpage for each BSP must contain a link to the testing data generated for every image contained in a released BSP.  For the BSPs tested by Yocto QA, the QA test report should be the one linked to for those BSPs.&lt;br /&gt;
&lt;br /&gt;
=== Image Verification ===&lt;br /&gt;
&lt;br /&gt;
For every BSP image contained in a tarball released on the Yocto website, it must be verified that the image can be independently generated from scratch (including downloads) using the released metadata.&lt;br /&gt;
&lt;br /&gt;
Customers must (and have, and will) be able to verify that the images contained in the release tarball can in fact be generated from the combination of the metadata contained in the BSP tarball and the set of packages downloaded by the build (from a scratch build) process to create those images. &lt;br /&gt;
&lt;br /&gt;
In practice, this means that the autobuilder maintainer needs to supply the settings required to generate the BSP to the person verifiying the image.  If the release tarball is generated by some other process, the BSP maintainer needs to supply that information.&lt;br /&gt;
* Note that all images released on the website must contain a time-limited kernel and this must be taken into account when verifying the image.&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9759</id>
		<title>Meta-intel Release Process</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9759"/>
		<updated>2013-04-23T17:16:06Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Image Verification */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;meta-intel releases happen with the same cadence that poky releases happen, though the actual release may be staggered with respect to the associated poky release.  We now attempt to co-release with poky, or at least have everything ready to co-release, but the actual release decision may dictate that we don&#039;t actually co-release.  The meta-intel release may also be staggered simply because meta-intel needs the extra time to stabilize against the associated poky release.&lt;br /&gt;
&lt;br /&gt;
This pages attempts to capture the meta-intel release process as it exists - it isn&#039;t meant to be an official or binding document.&lt;br /&gt;
&lt;br /&gt;
Also, this process only addresses the BSPs built and released by the Yocto Autobuilder team, and tested by the Yocto QA team - it doesn&#039;t address the release process for any BSPs that are managed outside of that process, such as the ISG BSPs, which may be built using a separate autobuilder and tested by ISG, i.e. which have their own release process, though their metadata may exist within the meta-intel and linux-yocto repositories.&lt;br /&gt;
&lt;br /&gt;
=== Release Notes ===&lt;br /&gt;
&lt;br /&gt;
Currently, the &#039;release notes&#039; for a BSP consist of the information found on the web page for the BSP in the &#039;Downloads&#039; section for the BSP, and essentially consists of the BSP&#039;s README along with a &#039;Layer-Specific Notes&#039; section, which is tacked on to the end of the page.&lt;br /&gt;
&lt;br /&gt;
* The Yocto documentation and website maintainers will be responsible for the content of the BSP pages and will ask the BSP maintainer(s) for any additional information needed for a particular BSP&lt;br /&gt;
* Normally the only thing needed from the BSP maintainer(s) are the &#039;Layer-Specific Notes&#039; for a BSP, which the BSP maintainers should supply to the documentation and website maintainers unsolicited as part of the release process.&lt;br /&gt;
** Any layer-specific notes that affect multiple or all BSPs should be attached to each BSP separately in the &#039;Layer-Specific Notes&#039; section.&lt;br /&gt;
* The title used for the BSP on the website is retrieved by the documentation and website maintainers from the BSP&#039;s WEBTITLE field in the BSP&#039;s machine.conf, and should therefore reflect accurately how the BSP is identified on the website.  This may be a string defined by marketing, and should at least be approved by marketing.&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
According to the Yocto Project compliance requirements, no meta-intel BSP can be released without testing data.  The webpage for each BSP must contain a link to the testing data generated for every image contained in a released BSP.  For the BSPs tested by Yocto QA, the QA test report should be the one linked to for those BSPs.&lt;br /&gt;
&lt;br /&gt;
=== Image Verification ===&lt;br /&gt;
&lt;br /&gt;
For every BSP image contained in a tarball released on the Yocto website, it must be verified that the image can be independently generated from scratch (including downloads) using the released metadata.&lt;br /&gt;
&lt;br /&gt;
Customers must (and have, and will) be able to verify that the images contained in the release tarball can in fact be generated from the combination of the metadata contained in the BSP tarball and the set of packages downloaded by the build (from a scratch build) process to create those images. &lt;br /&gt;
&lt;br /&gt;
In practice, this means that the autobuilder maintainer needs to supply the settings required to genrerate the BSP to the person verifiying the image.  If the release tarball is generated by some other process, the BSP maintainer needs to supply that information.&lt;br /&gt;
* Note that all images released on the website must contain a time-limited kernel and this must be taken into account when verifying the image.&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9758</id>
		<title>Meta-intel Release Process</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9758"/>
		<updated>2013-04-23T17:00:28Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;meta-intel releases happen with the same cadence that poky releases happen, though the actual release may be staggered with respect to the associated poky release.  We now attempt to co-release with poky, or at least have everything ready to co-release, but the actual release decision may dictate that we don&#039;t actually co-release.  The meta-intel release may also be staggered simply because meta-intel needs the extra time to stabilize against the associated poky release.&lt;br /&gt;
&lt;br /&gt;
This pages attempts to capture the meta-intel release process as it exists - it isn&#039;t meant to be an official or binding document.&lt;br /&gt;
&lt;br /&gt;
Also, this process only addresses the BSPs built and released by the Yocto Autobuilder team, and tested by the Yocto QA team - it doesn&#039;t address the release process for any BSPs that are managed outside of that process, such as the ISG BSPs, which may be built using a separate autobuilder and tested by ISG, i.e. which have their own release process, though their metadata may exist within the meta-intel and linux-yocto repositories.&lt;br /&gt;
&lt;br /&gt;
=== Release Notes ===&lt;br /&gt;
&lt;br /&gt;
Currently, the &#039;release notes&#039; for a BSP consist of the information found on the web page for the BSP in the &#039;Downloads&#039; section for the BSP, and essentially consists of the BSP&#039;s README along with a &#039;Layer-Specific Notes&#039; section, which is tacked on to the end of the page.&lt;br /&gt;
&lt;br /&gt;
* The Yocto documentation and website maintainers will be responsible for the content of the BSP pages and will ask the BSP maintainer(s) for any additional information needed for a particular BSP&lt;br /&gt;
* Normally the only thing needed from the BSP maintainer(s) are the &#039;Layer-Specific Notes&#039; for a BSP, which the BSP maintainers should supply to the documentation and website maintainers unsolicited as part of the release process.&lt;br /&gt;
** Any layer-specific notes that affect multiple or all BSPs should be attached to each BSP separately in the &#039;Layer-Specific Notes&#039; section.&lt;br /&gt;
* The title used for the BSP on the website is retrieved by the documentation and website maintainers from the BSP&#039;s WEBTITLE field in the BSP&#039;s machine.conf, and should therefore reflect accurately how the BSP is identified on the website.  This may be a string defined by marketing, and should at least be approved by marketing.&lt;br /&gt;
&lt;br /&gt;
=== Testing ===&lt;br /&gt;
&lt;br /&gt;
According to the Yocto Project compliance requirements, no meta-intel BSP can be released without testing data.  The webpage for each BSP must contain a link to the testing data generated for every image contained in a released BSP.  For the BSPs tested by Yocto QA, the QA test report should be the one linked to for those BSPs.&lt;br /&gt;
&lt;br /&gt;
=== Image Verification ===&lt;br /&gt;
&lt;br /&gt;
For every BSP image contained in a tarball released on the Yocto website, it must be verified that the image can be independently generated from scratch (including downloads) using the released metadata.  In practice, this means that the autobuilder maintainer needs to supply the settings required to genrerate the BSP to the person verifiying the image.  If the release tarball is generated by some other process, the BSP maintainer needs to supply that information.&lt;br /&gt;
* Note that all images released on the website must contain a time-limited kernel and this must be taken into account when verifying the image.&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9757</id>
		<title>Meta-intel Release Process</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9757"/>
		<updated>2013-04-23T16:41:59Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Release Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;meta-intel releases happen with the same cadence that poky releases happen, though the actual release may be staggered with respect to the associated poky release.  We now attempt to co-release with poky, or at least have everything ready to co-release, but the actual release decision may dictate that we don&#039;t actually co-release.  The meta-intel release may also be staggered simply because meta-intel needs the extra time to stabilize against the associated poky release.&lt;br /&gt;
&lt;br /&gt;
This pages attempts to capture the meta-intel release process as it exists - it isn&#039;t meant to be an official or binding document.&lt;br /&gt;
&lt;br /&gt;
Also, this process only addresses the BSPs built and released by the Yocto Autobuilder team, and tested by the Yocto QA team - it doesn&#039;t address the release process for any BSPs that are managed outside of that process, such as the ISG BSPs, which may be built using a separate autobuilder and tested by ISG, i.e. which have their own release process, though their metadata may exist within the meta-intel and linux-yocto repositories.&lt;br /&gt;
&lt;br /&gt;
=== Release Notes ===&lt;br /&gt;
&lt;br /&gt;
Currently, the &#039;release notes&#039; for a BSP consist of the information found on the web page for the BSP in the &#039;Downloads&#039; section for the BSP, and essentially consists of the BSP&#039;s README along with a &#039;Layer-Specific Notes&#039; section, which is tacked on to the end of the page.&lt;br /&gt;
&lt;br /&gt;
* The Yocto documentation and website maintainers will be responsible for the content of the BSP pages and will ask the BSP maintainer(s) for any additional information needed for a particular BSP&lt;br /&gt;
* Normally the only thing needed from the BSP maintainer(s) are the &#039;Layer-Specific Notes&#039; for a BSP, which the BSP maintainers should supply to the documentation and website maintainers unsolicited as part of the release process.&lt;br /&gt;
** Any layer-specific notes that affect multiple or all BSPs should be attached to each BSP separately in the &#039;Layer-Specific Notes&#039; section.&lt;br /&gt;
* The title used for the BSP on the website is retrieved by the documentation and website maintainers from the BSP&#039;s WEBTITLE field in the BSP&#039;s machine.conf, and should therefore reflect accurately how the BSP is identified on the website.  This may be a string defined by marketing, and should at least be approved by marketing.&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9755</id>
		<title>Meta-intel Release Process</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9755"/>
		<updated>2013-04-23T16:24:17Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;meta-intel releases happen with the same cadence that poky releases happen, though the actual release may be staggered with respect to the associated poky release.  We now attempt to co-release with poky, or at least have everything ready to co-release, but the actual release decision may dictate that we don&#039;t actually co-release.  The meta-intel release may also be staggered simply because meta-intel needs the extra time to stabilize against the associated poky release.&lt;br /&gt;
&lt;br /&gt;
This pages attempts to capture the meta-intel release process as it exists - it isn&#039;t meant to be an official or binding document.&lt;br /&gt;
&lt;br /&gt;
Also, this process only addresses the BSPs built and released by the Yocto Autobuilder team, and tested by the Yocto QA team - it doesn&#039;t address the release process for any BSPs that are managed outside of that process, such as the ISG BSPs, which may be built using a separate autobuilder and tested by ISG, i.e. which have their own release process, though their metadata may exist within the meta-intel and linux-yocto repositories.&lt;br /&gt;
&lt;br /&gt;
=== Release Notes ===&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9716</id>
		<title>Meta-intel Release Process</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Meta-intel_Release_Process&amp;diff=9716"/>
		<updated>2013-04-22T22:50:29Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: Created page with &amp;quot;Release Notes&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Release Notes&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=BSPs&amp;diff=9715</id>
		<title>BSPs</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=BSPs&amp;diff=9715"/>
		<updated>2013-04-22T22:49:41Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[Yocto BSP One-Stop Shop (Documentation Overview, Getting Started, FAQs, and more)]]&lt;br /&gt;
* [[Poky Contributions]]&lt;br /&gt;
* [[Poky NFS Root]]&lt;br /&gt;
* [[Wind River Kernel]]&lt;br /&gt;
* [[Merging Packages from OpenEmbedded]]&lt;br /&gt;
* [[How to turn on Poky Audio on Netbook]]&lt;br /&gt;
* [[How to Build Target Application in the Host Machine]]&lt;br /&gt;
* [[How to enable KVM for Poky qemu]]&lt;br /&gt;
* [[Yocto BSP Summit Presentation]]&lt;br /&gt;
* [[Yocto BSP Tools Documentation]]&lt;br /&gt;
* [[Transcript: from git checkout to qemu desktop]]&lt;br /&gt;
* [[Transcript: from git checkout to meta-intel BSP]]&lt;br /&gt;
* [[Transcript: Using the Yocto BSP tools to create a qemu BSP]]&lt;br /&gt;
* [[Transcript: Using the Yocto BSP tools to manage kernel patches and config items]]&lt;br /&gt;
* [[Transcript: Using the Yocto BSP tools to create a meta-intel BSP]]&lt;br /&gt;
* [[BKM: starting a new BSP]]&lt;br /&gt;
* [[Transcript: creating one generic Atom BSP from another]]&lt;br /&gt;
* [[BKM: improve qemu performance]]&lt;br /&gt;
* [[Last Known Good Commits for meta-intel]]&lt;br /&gt;
* [[meta-intel Release Process]]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8558</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8558"/>
		<updated>2013-01-27T23:40:52Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* operf */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
perf isn&#039;t restricted to the fixed set of static tracepoints listed by &#039;perf list&#039;.  Users can also add their own &#039;dynamic&#039; tracepoints anywhere in the kernel.  For instance, suppose we want to define our own tracepoint on do_fork().  We can do that using the &#039;perf probe&#039; perf subcommand: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; 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 [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem section]:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== operf ====&lt;br /&gt;
On systems with a kernel that supports it, you can more simply use the &#039;operf&#039; command to record profiles.  &#039;operf&#039; also allows you to easily profile a single application by running it as the last part of the &#039;operf&#039; command.  You can tell if your kernel supports &#039;operf&#039; by simply running it with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# operf&lt;br /&gt;
 usage: operf [ options ] [ --system-wide | --pid &amp;lt;pid&amp;gt; | [ command [ args ] ] ]&lt;br /&gt;
 See operf man page for details.&lt;br /&gt;
&lt;br /&gt;
If it doesn&#039;t support operf, you&#039;ll get a message that says the kernel doesn&#039;t support it.  You can run a system-wide profile by using operf with the -s (system-wide) option:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# operf -k /boot/vmlinux-`uname -r` -s -g&lt;br /&gt;
 operf: Profiler started&lt;br /&gt;
 operf: Press Ctl-c or &#039;kill -SIGINT 1222&#039; to stop profiling&lt;br /&gt;
 ^C* * * * WARNING: Profiling rate was throttled back by the kernel * * * *&lt;br /&gt;
 The number of samples actually recorded is less than expected, but is&lt;br /&gt;
 probably still statistically valid.  Decreasing the sampling rate is the&lt;br /&gt;
 best option if you want to avoid throttling. &lt;br /&gt;
 &lt;br /&gt;
 See the /home/root/oprofile_data/samples/operf.log file for statistics about lost samples. &lt;br /&gt;
 &lt;br /&gt;
 Profiling done.&lt;br /&gt;
&lt;br /&gt;
You can use &#039;opreport&#039; to get the results just as you would with &#039;legacy oprofile&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 Using /home/root/oprofile_data/samples/ for samples directory.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 90000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
   samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
      3431 99.2766 operf &lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     1822 53.1041 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
 	      809 23.5791 operf&lt;br /&gt;
 	      680 19.8193 libc-2.16.so&lt;br /&gt;
 	      117  3.4101 libstdc++.so.6.0.17&lt;br /&gt;
 	        3  0.0874 emgd&lt;br /&gt;
        13  0.3762 dropbearmulti&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
 	        9 69.2308 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
 	        3 23.0769 dropbearmulti&lt;br /&gt;
 	        1  7.6923 libc-2.16.so&lt;br /&gt;
        11  0.3183 matchbox-terminal&lt;br /&gt;
  	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        6 54.5455 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
 	        3 27.2727 libglib-2.0.so.0.3400.3&lt;br /&gt;
 	        1  9.0909 libc-2.16.so&lt;br /&gt;
 	        1  9.0909 librt-2.16.so&lt;br /&gt;
         1  0.0289 init.sysvinit&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        1 100.000 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
&lt;br /&gt;
You can also, as always, display the results with callgraphs:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph&lt;br /&gt;
 Using /home/root/oprofile_data/samples/ for samples directory.&lt;br /&gt;
 warning: /emgd could not be found.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 90000&lt;br /&gt;
 samples  %        image name               app name                 symbol name&lt;br /&gt;
 -------------------------------------------------------------------------------&lt;br /&gt;
 809      23.4086  operf                    operf                    /usr/bin/operf&lt;br /&gt;
   809      100.000  operf                    operf                    /usr/bin/operf [self]&lt;br /&gt;
 -------------------------------------------------------------------------------&lt;br /&gt;
 680      19.6759  libc-2.16.so             operf                    /lib/libc-2.16.so&lt;br /&gt;
   680      100.000  libc-2.16.so             operf                    /lib/libc-2.16.so [self]&lt;br /&gt;
 -------------------------------------------------------------------------------&lt;br /&gt;
 117       3.3854  libstdc++.so.6.0.17      operf                    /usr/lib/libstdc++.so.6.0.17&lt;br /&gt;
   117      100.000  libstdc++.so.6.0.17      operf                    /usr/lib/libstdc++.so.6.0.17 [self]&lt;br /&gt;
 -------------------------------------------------------------------------------&lt;br /&gt;
   1         0.4717  vmlinux-3.4.26-yocto-standard operf                    kmem_cache_alloc&lt;br /&gt;
   1         0.4717  vmlinux-3.4.26-yocto-standard operf                    ext3_getblk&lt;br /&gt;
   4         1.8868  vmlinux-3.4.26-yocto-standard operf                    do_mpage_readpage&lt;br /&gt;
   5         2.3585  vmlinux-3.4.26-yocto-standard operf                    kmem_cache_alloc_trace&lt;br /&gt;
   95       44.8113  vmlinux-3.4.26-yocto-standard operf                    get_page_from_freelist&lt;br /&gt;
   106      50.0000  vmlinux-3.4.26-yocto-standard operf                    memset&lt;br /&gt;
 106       3.0671  vmlinux-3.4.26-yocto-standard operf                    memset&lt;br /&gt;
   106      50.0000  vmlinux-3.4.26-yocto-standard operf                    memset&lt;br /&gt;
   106      50.0000  vmlinux-3.4.26-yocto-standard operf                    memset [self]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of recording a single application:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# operf -k /boot/vmlinux-`uname -r` -g /usr/bin/wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 operf: Profiler started&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |****************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 See the /home/root/oprofile_data/samples/operf.log file for statistics about lost samples. &lt;br /&gt;
 &lt;br /&gt;
 Profiling done.&lt;br /&gt;
&lt;br /&gt;
And again display the results with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 Using /home/root/oprofile_data/samples/ for samples directory.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 90000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
   samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
     48835 100.000 wget &lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    45778 93.7401 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
 	     1921  3.9337 libc-2.16.so&lt;br /&gt;
 	     1097  2.2463 busybox&lt;br /&gt;
 	       33  0.0676 emgd&lt;br /&gt;
 	        4  0.0082 ld-2.16.so&lt;br /&gt;
 	        1  0.0020 libnss_files-2.16.so&lt;br /&gt;
 	        1  0.0020 libresolv-2.16.so&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a userspace trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
For lttng userspace tracing, you need to have a properly instrumented userspace program.  For this example, we&#039;ll use the &#039;hello&#039; test program generated by the lttng-ust build.&lt;br /&gt;
&lt;br /&gt;
The &#039;hello&#039; test program isn&#039;t installed on the rootfs by the lttng-ust build, so we need to copy it over manually.  First cd into the build directory that contains the hello executable:&lt;br /&gt;
&lt;br /&gt;
 $ cd build/tmp/work/core2-poky-linux/lttng-ust/2.0.5-r0/git/tests/hello/.libs&lt;br /&gt;
&lt;br /&gt;
Copy that over to the target machine:&lt;br /&gt;
&lt;br /&gt;
 $ scp hello root@192.168.1.20:&lt;br /&gt;
&lt;br /&gt;
You now have the instrumented lttng &#039;hello world&#039; test program on the target, ready to test. &lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Session auto-20190303-021943 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all userspace events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --userspace --all&lt;br /&gt;
 All UST events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Run the instrumented hello world program:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ./hello&lt;br /&gt;
 Hello, World!&lt;br /&gt;
 Tracing...  done.&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4,  seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20190303-021943 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
It&#039;s also possible to trace block I/O using only [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem], which can be useful for casual tracing if you don&#039;t want bother dealing with the userspace tools.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve selected the device(s) you want to trace, selecting the &#039;blk&#039; tracer will turn the blk tracer on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
Execute the workload you&#039;re interested in:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
And look at the output (note here that we&#039;re using &#039;trace_pipe&#039; instead of trace to capture this trace - this allows us to wait around on the pipe for data to appear):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
And this turns off tracing for the specified device:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8557</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8557"/>
		<updated>2013-01-27T23:34:51Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* operf */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
perf isn&#039;t restricted to the fixed set of static tracepoints listed by &#039;perf list&#039;.  Users can also add their own &#039;dynamic&#039; tracepoints anywhere in the kernel.  For instance, suppose we want to define our own tracepoint on do_fork().  We can do that using the &#039;perf probe&#039; perf subcommand: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; 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 [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem section]:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== operf ====&lt;br /&gt;
On systems with a kernel that supports it, you can more simply use the &#039;operf&#039; command to record profiles.  &#039;operf&#039; also allows you to easily profile a single application by running it as the last part of the &#039;operf&#039; command.  You can tell if your kernel supports &#039;operf&#039; by simply running it with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# operf&lt;br /&gt;
 usage: operf [ options ] [ --system-wide | --pid &amp;lt;pid&amp;gt; | [ command [ args ] ] ]&lt;br /&gt;
 See operf man page for details.&lt;br /&gt;
&lt;br /&gt;
If it doesn&#039;t support operf, you&#039;ll get a message that says the kernel doesn&#039;t support it.  You can run a system-wide profile by using operf with the -s (system-wide) option:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# operf -k /boot/vmlinux-`uname -r` -s -g&lt;br /&gt;
 operf: Profiler started&lt;br /&gt;
 operf: Press Ctl-c or &#039;kill -SIGINT 1222&#039; to stop profiling&lt;br /&gt;
 ^C* * * * WARNING: Profiling rate was throttled back by the kernel * * * *&lt;br /&gt;
 The number of samples actually recorded is less than expected, but is&lt;br /&gt;
 probably still statistically valid.  Decreasing the sampling rate is the&lt;br /&gt;
 best option if you want to avoid throttling. &lt;br /&gt;
 &lt;br /&gt;
 See the /home/root/oprofile_data/samples/operf.log file for statistics about lost samples. &lt;br /&gt;
 &lt;br /&gt;
 Profiling done.&lt;br /&gt;
&lt;br /&gt;
You can use &#039;opreport&#039; to get the results just as you would with &#039;legacy oprofile&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 Using /home/root/oprofile_data/samples/ for samples directory.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 90000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
   samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
      3431 99.2766 operf &lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     1822 53.1041 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
 	      809 23.5791 operf&lt;br /&gt;
 	      680 19.8193 libc-2.16.so&lt;br /&gt;
 	      117  3.4101 libstdc++.so.6.0.17&lt;br /&gt;
 	        3  0.0874 emgd&lt;br /&gt;
        13  0.3762 dropbearmulti&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
 	        9 69.2308 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
 	        3 23.0769 dropbearmulti&lt;br /&gt;
 	        1  7.6923 libc-2.16.so&lt;br /&gt;
        11  0.3183 matchbox-terminal&lt;br /&gt;
  	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        6 54.5455 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
 	        3 27.2727 libglib-2.0.so.0.3400.3&lt;br /&gt;
 	        1  9.0909 libc-2.16.so&lt;br /&gt;
 	        1  9.0909 librt-2.16.so&lt;br /&gt;
         1  0.0289 init.sysvinit&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        1 100.000 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
&lt;br /&gt;
Display with callgraph:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph&lt;br /&gt;
 Using /home/root/oprofile_data/samples/ for samples directory.&lt;br /&gt;
 warning: /emgd could not be found.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 90000&lt;br /&gt;
 samples  %        image name               app name                 symbol name&lt;br /&gt;
 -------------------------------------------------------------------------------&lt;br /&gt;
 809      23.4086  operf                    operf                    /usr/bin/operf&lt;br /&gt;
   809      100.000  operf                    operf                    /usr/bin/operf [self]&lt;br /&gt;
 -------------------------------------------------------------------------------&lt;br /&gt;
 680      19.6759  libc-2.16.so             operf                    /lib/libc-2.16.so&lt;br /&gt;
   680      100.000  libc-2.16.so             operf                    /lib/libc-2.16.so [self]&lt;br /&gt;
 -------------------------------------------------------------------------------&lt;br /&gt;
 117       3.3854  libstdc++.so.6.0.17      operf                    /usr/lib/libstdc++.so.6.0.17&lt;br /&gt;
   117      100.000  libstdc++.so.6.0.17      operf                    /usr/lib/libstdc++.so.6.0.17 [self]&lt;br /&gt;
 -------------------------------------------------------------------------------&lt;br /&gt;
   1         0.4717  vmlinux-3.4.26-yocto-standard operf                    kmem_cache_alloc&lt;br /&gt;
   1         0.4717  vmlinux-3.4.26-yocto-standard operf                    ext3_getblk&lt;br /&gt;
   4         1.8868  vmlinux-3.4.26-yocto-standard operf                    do_mpage_readpage&lt;br /&gt;
   5         2.3585  vmlinux-3.4.26-yocto-standard operf                    kmem_cache_alloc_trace&lt;br /&gt;
   95       44.8113  vmlinux-3.4.26-yocto-standard operf                    get_page_from_freelist&lt;br /&gt;
   106      50.0000  vmlinux-3.4.26-yocto-standard operf                    memset&lt;br /&gt;
 106       3.0671  vmlinux-3.4.26-yocto-standard operf                    memset&lt;br /&gt;
   106      50.0000  vmlinux-3.4.26-yocto-standard operf                    memset&lt;br /&gt;
   106      50.0000  vmlinux-3.4.26-yocto-standard operf                    memset [self]&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a userspace trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
For lttng userspace tracing, you need to have a properly instrumented userspace program.  For this example, we&#039;ll use the &#039;hello&#039; test program generated by the lttng-ust build.&lt;br /&gt;
&lt;br /&gt;
The &#039;hello&#039; test program isn&#039;t installed on the rootfs by the lttng-ust build, so we need to copy it over manually.  First cd into the build directory that contains the hello executable:&lt;br /&gt;
&lt;br /&gt;
 $ cd build/tmp/work/core2-poky-linux/lttng-ust/2.0.5-r0/git/tests/hello/.libs&lt;br /&gt;
&lt;br /&gt;
Copy that over to the target machine:&lt;br /&gt;
&lt;br /&gt;
 $ scp hello root@192.168.1.20:&lt;br /&gt;
&lt;br /&gt;
You now have the instrumented lttng &#039;hello world&#039; test program on the target, ready to test. &lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Session auto-20190303-021943 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all userspace events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --userspace --all&lt;br /&gt;
 All UST events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Run the instrumented hello world program:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ./hello&lt;br /&gt;
 Hello, World!&lt;br /&gt;
 Tracing...  done.&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4,  seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20190303-021943 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
It&#039;s also possible to trace block I/O using only [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem], which can be useful for casual tracing if you don&#039;t want bother dealing with the userspace tools.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve selected the device(s) you want to trace, selecting the &#039;blk&#039; tracer will turn the blk tracer on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
Execute the workload you&#039;re interested in:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
And look at the output (note here that we&#039;re using &#039;trace_pipe&#039; instead of trace to capture this trace - this allows us to wait around on the pipe for data to appear):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
And this turns off tracing for the specified device:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8556</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8556"/>
		<updated>2013-01-27T23:31:39Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* operf */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
perf isn&#039;t restricted to the fixed set of static tracepoints listed by &#039;perf list&#039;.  Users can also add their own &#039;dynamic&#039; tracepoints anywhere in the kernel.  For instance, suppose we want to define our own tracepoint on do_fork().  We can do that using the &#039;perf probe&#039; perf subcommand: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; 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 [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem section]:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== operf ====&lt;br /&gt;
On systems with a kernel that supports it, you can more simply use the &#039;operf&#039; command to record profiles.  &#039;operf&#039; also allows you to easily profile a single application by running it as the last part of the &#039;operf&#039; command.  You can tell if your kernel supports &#039;operf&#039; by simply running it with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# operf&lt;br /&gt;
 usage: operf [ options ] [ --system-wide | --pid &amp;lt;pid&amp;gt; | [ command [ args ] ] ]&lt;br /&gt;
 See operf man page for details.&lt;br /&gt;
&lt;br /&gt;
If it doesn&#039;t support operf, you&#039;ll get a message that says the kernel doesn&#039;t support it.  You can run a system-wide profile by using operf with the -s (system-wide) option:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# operf -k /boot/vmlinux-`uname -r` -s -g&lt;br /&gt;
 operf: Profiler started&lt;br /&gt;
 operf: Press Ctl-c or &#039;kill -SIGINT 1222&#039; to stop profiling&lt;br /&gt;
 ^C* * * * WARNING: Profiling rate was throttled back by the kernel * * * *&lt;br /&gt;
 The number of samples actually recorded is less than expected, but is&lt;br /&gt;
 probably still statistically valid.  Decreasing the sampling rate is the&lt;br /&gt;
 best option if you want to avoid throttling. &lt;br /&gt;
 &lt;br /&gt;
 See the /home/root/oprofile_data/samples/operf.log file for statistics about lost samples. &lt;br /&gt;
 &lt;br /&gt;
 Profiling done.&lt;br /&gt;
&lt;br /&gt;
You can use &#039;opreport&#039; to get the results just as you would with &#039;legacy oprofile&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 Using /home/root/oprofile_data/samples/ for samples directory.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 90000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
   samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
      3431 99.2766 operf &lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     1822 53.1041 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
 	      809 23.5791 operf&lt;br /&gt;
 	      680 19.8193 libc-2.16.so&lt;br /&gt;
 	      117  3.4101 libstdc++.so.6.0.17&lt;br /&gt;
 	        3  0.0874 emgd&lt;br /&gt;
        13  0.3762 dropbearmulti&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
 	        9 69.2308 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
 	        3 23.0769 dropbearmulti&lt;br /&gt;
 	        1  7.6923 libc-2.16.so&lt;br /&gt;
        11  0.3183 matchbox-terminal&lt;br /&gt;
  	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        6 54.5455 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
 	        3 27.2727 libglib-2.0.so.0.3400.3&lt;br /&gt;
 	        1  9.0909 libc-2.16.so&lt;br /&gt;
 	        1  9.0909 librt-2.16.so&lt;br /&gt;
         1  0.0289 init.sysvinit&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        1 100.000 vmlinux-3.4.26-yocto-standard&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a userspace trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
For lttng userspace tracing, you need to have a properly instrumented userspace program.  For this example, we&#039;ll use the &#039;hello&#039; test program generated by the lttng-ust build.&lt;br /&gt;
&lt;br /&gt;
The &#039;hello&#039; test program isn&#039;t installed on the rootfs by the lttng-ust build, so we need to copy it over manually.  First cd into the build directory that contains the hello executable:&lt;br /&gt;
&lt;br /&gt;
 $ cd build/tmp/work/core2-poky-linux/lttng-ust/2.0.5-r0/git/tests/hello/.libs&lt;br /&gt;
&lt;br /&gt;
Copy that over to the target machine:&lt;br /&gt;
&lt;br /&gt;
 $ scp hello root@192.168.1.20:&lt;br /&gt;
&lt;br /&gt;
You now have the instrumented lttng &#039;hello world&#039; test program on the target, ready to test. &lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Session auto-20190303-021943 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all userspace events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --userspace --all&lt;br /&gt;
 All UST events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Run the instrumented hello world program:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ./hello&lt;br /&gt;
 Hello, World!&lt;br /&gt;
 Tracing...  done.&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4,  seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20190303-021943 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
It&#039;s also possible to trace block I/O using only [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem], which can be useful for casual tracing if you don&#039;t want bother dealing with the userspace tools.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve selected the device(s) you want to trace, selecting the &#039;blk&#039; tracer will turn the blk tracer on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
Execute the workload you&#039;re interested in:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
And look at the output (note here that we&#039;re using &#039;trace_pipe&#039; instead of trace to capture this trace - this allows us to wait around on the pipe for data to appear):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
And this turns off tracing for the specified device:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8555</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8555"/>
		<updated>2013-01-27T23:28:45Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* oprofile */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
perf isn&#039;t restricted to the fixed set of static tracepoints listed by &#039;perf list&#039;.  Users can also add their own &#039;dynamic&#039; tracepoints anywhere in the kernel.  For instance, suppose we want to define our own tracepoint on do_fork().  We can do that using the &#039;perf probe&#039; perf subcommand: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; 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 [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem section]:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== operf ====&lt;br /&gt;
On systems with a kernel that supports it, you can more simply use the &#039;operf&#039; command to record profiles.  &#039;operf&#039; also allows you to easily profile a single application by running it as the last part of the &#039;operf&#039; command.  You can tell if your kernel supports &#039;operf&#039; by simply running it with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# operf&lt;br /&gt;
 usage: operf [ options ] [ --system-wide | --pid &amp;lt;pid&amp;gt; | [ command [ args ] ] ]&lt;br /&gt;
 See operf man page for details.&lt;br /&gt;
&lt;br /&gt;
If it doesn&#039;t support operf, you&#039;ll get a message that says the kernel doesn&#039;t support it.  You can run a system-wide profile by using operf with the -s (system-wide) option:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# operf -k /boot/vmlinux-`uname -r` -s -g&lt;br /&gt;
 operf: Profiler started&lt;br /&gt;
 operf: Press Ctl-c or &#039;kill -SIGINT 1222&#039; to stop profiling&lt;br /&gt;
 ^C* * * * WARNING: Profiling rate was throttled back by the kernel * * * *&lt;br /&gt;
 The number of samples actually recorded is less than expected, but is&lt;br /&gt;
 probably still statistically valid.  Decreasing the sampling rate is the&lt;br /&gt;
 best option if you want to avoid throttling. &lt;br /&gt;
 &lt;br /&gt;
 See the /home/root/oprofile_data/samples/operf.log file for statistics about lost samples. &lt;br /&gt;
 &lt;br /&gt;
 Profiling done.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a userspace trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
For lttng userspace tracing, you need to have a properly instrumented userspace program.  For this example, we&#039;ll use the &#039;hello&#039; test program generated by the lttng-ust build.&lt;br /&gt;
&lt;br /&gt;
The &#039;hello&#039; test program isn&#039;t installed on the rootfs by the lttng-ust build, so we need to copy it over manually.  First cd into the build directory that contains the hello executable:&lt;br /&gt;
&lt;br /&gt;
 $ cd build/tmp/work/core2-poky-linux/lttng-ust/2.0.5-r0/git/tests/hello/.libs&lt;br /&gt;
&lt;br /&gt;
Copy that over to the target machine:&lt;br /&gt;
&lt;br /&gt;
 $ scp hello root@192.168.1.20:&lt;br /&gt;
&lt;br /&gt;
You now have the instrumented lttng &#039;hello world&#039; test program on the target, ready to test. &lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Session auto-20190303-021943 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all userspace events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --userspace --all&lt;br /&gt;
 All UST events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Run the instrumented hello world program:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ./hello&lt;br /&gt;
 Hello, World!&lt;br /&gt;
 Tracing...  done.&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4,  seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20190303-021943 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
It&#039;s also possible to trace block I/O using only [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem], which can be useful for casual tracing if you don&#039;t want bother dealing with the userspace tools.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve selected the device(s) you want to trace, selecting the &#039;blk&#039; tracer will turn the blk tracer on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
Execute the workload you&#039;re interested in:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
And look at the output (note here that we&#039;re using &#039;trace_pipe&#039; instead of trace to capture this trace - this allows us to wait around on the pipe for data to appear):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
And this turns off tracing for the specified device:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8341</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8341"/>
		<updated>2013-01-08T21:55:48Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Collecting and viewing a userspace trace on the target (inside a shell) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
perf isn&#039;t restricted to the fixed set of static tracepoints listed by &#039;perf list&#039;.  Users can also add their own &#039;dynamic&#039; tracepoints anywhere in the kernel.  For instance, suppose we want to define our own tracepoint on do_fork().  We can do that using the &#039;perf probe&#039; perf subcommand: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; 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 [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem section]:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a userspace trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
For lttng userspace tracing, you need to have a properly instrumented userspace program.  For this example, we&#039;ll use the &#039;hello&#039; test program generated by the lttng-ust build.&lt;br /&gt;
&lt;br /&gt;
The &#039;hello&#039; test program isn&#039;t installed on the rootfs by the lttng-ust build, so we need to copy it over manually.  First cd into the build directory that contains the hello executable:&lt;br /&gt;
&lt;br /&gt;
 $ cd build/tmp/work/core2-poky-linux/lttng-ust/2.0.5-r0/git/tests/hello/.libs&lt;br /&gt;
&lt;br /&gt;
Copy that over to the target machine:&lt;br /&gt;
&lt;br /&gt;
 $ scp hello root@192.168.1.20:&lt;br /&gt;
&lt;br /&gt;
You now have the instrumented lttng &#039;hello world&#039; test program on the target, ready to test. &lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Session auto-20190303-021943 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all userspace events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --userspace --all&lt;br /&gt;
 All UST events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Run the instrumented hello world program:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ./hello&lt;br /&gt;
 Hello, World!&lt;br /&gt;
 Tracing...  done.&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4,  seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20190303-021943 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
It&#039;s also possible to trace block I/O using only [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem], which can be useful for casual tracing if you don&#039;t want bother dealing with the userspace tools.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve selected the device(s) you want to trace, selecting the &#039;blk&#039; tracer will turn the blk tracer on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
Execute the workload you&#039;re interested in:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
And look at the output (note here that we&#039;re using &#039;trace_pipe&#039; instead of trace to capture this trace - this allows us to wait around on the pipe for data to appear):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
And this turns off tracing for the specified device:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8340</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8340"/>
		<updated>2013-01-08T21:49:44Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Collecting and Viewing Traces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
perf isn&#039;t restricted to the fixed set of static tracepoints listed by &#039;perf list&#039;.  Users can also add their own &#039;dynamic&#039; tracepoints anywhere in the kernel.  For instance, suppose we want to define our own tracepoint on do_fork().  We can do that using the &#039;perf probe&#039; perf subcommand: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; 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 [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem section]:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a userspace trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Session auto-20190303-021943 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all userspace events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --userspace --all&lt;br /&gt;
 All UST events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
Run the instrumented hello world program:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ./hello&lt;br /&gt;
 Hello, World!&lt;br /&gt;
 Tracing...  done.&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20190303-021943&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4,  seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 [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 = &amp;quot;test&amp;quot;, _seqfield1_length = 4, seqfield1 = [ [0] = 116, [1] = 101, [2] = 115, [3] = 116 ], _seqfield2_length = 4, seqfield2 = &amp;quot;test&amp;quot;, stringfield = &amp;quot;test&amp;quot;, floatfield = 2222, doublefield = 2, boolfield = 1 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20190303-021943 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
It&#039;s also possible to trace block I/O using only [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem], which can be useful for casual tracing if you don&#039;t want bother dealing with the userspace tools.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve selected the device(s) you want to trace, selecting the &#039;blk&#039; tracer will turn the blk tracer on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
Execute the workload you&#039;re interested in:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
And look at the output (note here that we&#039;re using &#039;trace_pipe&#039; instead of trace to capture this trace - this allows us to wait around on the pipe for data to appear):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
And this turns off tracing for the specified device:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Last_Known_Good_Commits_for_meta-intel&amp;diff=8060</id>
		<title>Last Known Good Commits for meta-intel</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Last_Known_Good_Commits_for_meta-intel&amp;diff=8060"/>
		<updated>2012-11-20T17:36:52Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: Created page with &amp;quot;This page simply tracks the last poky and meta-intel commits that were verified to build and boot into sato for each meta-intel BSP.  The format is just suggested, please change ...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page simply tracks the last poky and meta-intel commits that were verified to build and boot into sato for each meta-intel BSP.&lt;br /&gt;
&lt;br /&gt;
The format is just suggested, please change it as you see fit.  Also there&#039;s no reason to not add more testing information beyond that it booted on sato, but please try to keep the display simple.&lt;br /&gt;
&lt;br /&gt;
*crownbay:&lt;br /&gt;
**meta-intel/master commit: fffffff762f20ca6988034f2e5aab2b9b7be1b70&lt;br /&gt;
**poky commit: fffffff762f20ca6988034f2e5aab2b9b7be1b70&lt;br /&gt;
&lt;br /&gt;
*sugarbay:&lt;br /&gt;
**meta-intel/master commit: fffffff762f20ca6988034f2e5aab2b9b7be1b70&lt;br /&gt;
**poky commit: fffffff762f20ca6988034f2e5aab2b9b7be1b70&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=BSPs&amp;diff=8059</id>
		<title>BSPs</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=BSPs&amp;diff=8059"/>
		<updated>2012-11-20T17:29:51Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[Yocto BSP One-Stop Shop (Documentation Overview, Getting Started, FAQs, and more)]]&lt;br /&gt;
* [[Poky Contributions]]&lt;br /&gt;
* [[Poky NFS Root]]&lt;br /&gt;
* [[Wind River Kernel]]&lt;br /&gt;
* [[Merging Packages from OpenEmbedded]]&lt;br /&gt;
* [[How to turn on Poky Audio on Netbook]]&lt;br /&gt;
* [[How to Build Target Application in the Host Machine]]&lt;br /&gt;
* [[How to enable KVM for Poky qemu]]&lt;br /&gt;
* [[Yocto BSP Summit Presentation]]&lt;br /&gt;
* [[Yocto BSP Tools Documentation]]&lt;br /&gt;
* [[Transcript: from git checkout to qemu desktop]]&lt;br /&gt;
* [[Transcript: from git checkout to meta-intel BSP]]&lt;br /&gt;
* [[Transcript: Using the Yocto BSP tools to create a qemu BSP]]&lt;br /&gt;
* [[Transcript: Using the Yocto BSP tools to manage kernel patches and config items]]&lt;br /&gt;
* [[Transcript: Using the Yocto BSP tools to create a meta-intel BSP]]&lt;br /&gt;
* [[BKM: starting a new BSP]]&lt;br /&gt;
* [[Transcript: creating one generic Atom BSP from another]]&lt;br /&gt;
* [[BKM: improve qemu performance]]&lt;br /&gt;
* [[Last Known Good Commits for meta-intel]]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8048</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8048"/>
		<updated>2012-11-15T21:19:56Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Using dynamic tracepoints */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
perf isn&#039;t restricted to the fixed set of static tracepoints listed by &#039;perf list&#039;.  Users can also add their own &#039;dynamic&#039; tracepoints anywhere in the kernel.  For instance, suppose we want to define our own tracepoint on do_fork().  We can do that using the &#039;perf probe&#039; perf subcommand: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; 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 [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem section]:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
It&#039;s also possible to trace block I/O using only [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem], which can be useful for casual tracing if you don&#039;t want bother dealing with the userspace tools.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve selected the device(s) you want to trace, selecting the &#039;blk&#039; tracer will turn the blk tracer on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
Execute the workload you&#039;re interested in:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
And look at the output (note here that we&#039;re using &#039;trace_pipe&#039; instead of trace to capture this trace - this allows us to wait around on the pipe for data to appear):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
And this turns off tracing for the specified device:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8047</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8047"/>
		<updated>2012-11-15T21:17:06Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Using dynamic tracepoints */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
perf isn&#039;t restricted to the fixed set of static tracepoints listed by &#039;perf list&#039;.  Users can also add their own &#039;dynamic&#039; tracepoints anywhere in the kernel.  For instance, suppose we want to define our own tracepoint on do_fork().  We can do that using the &#039;perf probe&#039; perf subcommand: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
It&#039;s also possible to trace block I/O using only [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem], which can be useful for casual tracing if you don&#039;t want bother dealing with the userspace tools.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve selected the device(s) you want to trace, selecting the &#039;blk&#039; tracer will turn the blk tracer on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
Execute the workload you&#039;re interested in:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
And look at the output (note here that we&#039;re using &#039;trace_pipe&#039; instead of trace to capture this trace - this allows us to wait around on the pipe for data to appear):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
And this turns off tracing for the specified device:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8046</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8046"/>
		<updated>2012-11-15T15:32:25Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Tracing Block I/O via &amp;#039;ftrace&amp;#039; */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
It&#039;s also possible to trace block I/O using only [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem], which can be useful for casual tracing if you don&#039;t want bother dealing with the userspace tools.&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve selected the device(s) you want to trace, selecting the &#039;blk&#039; tracer will turn the blk tracer on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
Execute the workload you&#039;re interested in:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
And look at the output (note here that we&#039;re using &#039;trace_pipe&#039; instead of trace to capture this trace - this allows us to wait around on the pipe for data to appear):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
And this turns off tracing for the specified device:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8045</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8045"/>
		<updated>2012-11-15T05:34:11Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* perf */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8044</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8044"/>
		<updated>2012-11-15T04:56:43Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* trace-cmd/kernelshark */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
The tool is pretty self-explanatory, but for more detailed information on navigating through the data, see the &lt;br /&gt;
[http://rostedt.homelinux.com/kernelshark/ kernelshark website].&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8043</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8043"/>
		<updated>2012-11-15T04:54:36Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* trace-cmd/kernelshark */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
After doing that, we can start and stop the trace using the &#039;Run&#039; and &#039;Stop&#039; button on the lower right corner of the dialog (the same button will turn into the &#039;Stop&#039; button after the trace has started):&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice that the right-hand pane shows the exact trace-cmd command-line that&#039;s used to run the trace, along with the results of the trace-cmd run.&lt;br /&gt;
&lt;br /&gt;
Once the &#039;Stop&#039; button is pressed, the graphical view magically fills up with a colorful per-cpu display of the trace data, along with the detailed event listing below that:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
&lt;br /&gt;
Here&#039;s another example, this time a display resulting from tracing &#039;all events&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8042</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8042"/>
		<updated>2012-11-15T04:47:00Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* trace-cmd/kernelshark */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
To start a trace using kernelshark, first start kernelshark:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:~# kernelshark&lt;br /&gt;
&lt;br /&gt;
The bring up the &#039;Capture&#039; dialog by choosing from the kernelshark menu:&lt;br /&gt;
&lt;br /&gt;
 Capture | Record&lt;br /&gt;
&lt;br /&gt;
That will display the following dialog, which allows you to choose on or more events (or even one or more complete subsystems) to trace:&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
&lt;br /&gt;
Note that these are exactly the same set of events described in the previous [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] section, and in fact is where trace-cmd gets them for kernelshark.&lt;br /&gt;
&lt;br /&gt;
In the above screenshot, we&#039;ve decided to explore the graphics subsystem a bit and so have chosen to trace all the tracepoints contained within the &#039;i915&#039; and &#039;drm&#039; subsystems.&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8041</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8041"/>
		<updated>2012-11-15T04:32:21Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* The &amp;#039;trace events&amp;#039; subsystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
To again disable the kmalloc event, we need to send 0 to the enable file:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 0 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
You can enable any number of events or complete subsystems (by using the &#039;enable&#039; file in the subsystem directory) and get am arbitrarily fine-grained idea of what&#039;s going on in the system by enabling as many of the appropriate tracepoints as applicable.&lt;br /&gt;
&lt;br /&gt;
A number of the tools described in this HOWTO do just that, including trace-cmd and kernelshark in the next section.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8040</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8040"/>
		<updated>2012-11-15T04:26:46Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* The &amp;#039;trace events&amp;#039; subsystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The &#039;enable&#039; 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 &#039;trace&#039; file described previously.  For example, this turns on the kmalloc tracepoint:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# echo 1 &amp;gt; enable&lt;br /&gt;
&lt;br /&gt;
At the moment, we&#039;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:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo nop &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; tracing_on&lt;br /&gt;
&lt;br /&gt;
Now, if we look at the the &#039;trace&#039; file, we see nothing but the kmalloc events we just turned on:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 # tracer: nop&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 1897/1897   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
        dropbear-1465  [000] ...1 18154.620753: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621640: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18154.621656: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755583: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18154.755589: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354705: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.354711: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.673319: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.673525: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.674821: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.793014: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.793219: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.794147: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.936705: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18155.936910: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18155.937869: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
            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&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953777: kmalloc: call_site=ffffffff814192a3 ptr=ffff88001f822520 bytes_req=24 bytes_alloc=32 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
            Xorg-1264  [002] ...1 18155.953783: kmalloc: call_site=ffffffff81419edb ptr=ffff8800721a2f00 bytes_req=64 bytes_alloc=64 gfp_flags=GFP_KERNEL|GFP_ZERO&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.176053: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.176257: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.177717: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.399229: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d555800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
        dropbear-1465  [000] ...1 18156.399434: kmalloc: call_site=ffffffff816650d4 ptr=ffff8800729c3000 bytes_req=2048 bytes_alloc=2048 gfp_flags=GFP_KERNEL&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [000] ..s3 18156.400660: kmalloc: call_site=ffffffff81619b36 ptr=ffff88006d554800 bytes_req=512 bytes_alloc=512 gfp_flags=GFP_ATOMIC&lt;br /&gt;
 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&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8039</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8039"/>
		<updated>2012-11-15T04:15:14Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* The &amp;#039;trace events&amp;#039; subsystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
The &#039;format&#039; file for the 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 &#039;print fmt&#039; field that allows tools like ftrace to display the event as text.  Here&#039;s what the format of the kmalloc event looks like:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# cat format&lt;br /&gt;
 name: kmalloc&lt;br /&gt;
 ID: 313&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0;&lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long call_site;	offset:16;	size:8;	signed:0;&lt;br /&gt;
 	field:const void * ptr;	offset:24;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_req;	offset:32;	size:8;	signed:0;&lt;br /&gt;
 	field:size_t bytes_alloc;	offset:40;	size:8;	signed:0;&lt;br /&gt;
 	field:gfp_t gfp_flags;	offset:48;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;call_site=%lx ptr=%p bytes_req=%zu bytes_alloc=%zu gfp_flags=%s&amp;quot;, REC-&amp;gt;call_site, REC-&amp;gt;ptr, REC-&amp;gt;bytes_req, REC-&amp;gt;bytes_alloc,&lt;br /&gt;
 (REC-&amp;gt;gfp_flags) ? __print_flags(REC-&amp;gt;gfp_flags, &amp;quot;|&amp;quot;, {(unsigned long)(((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | ((&lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u) | (( gfp_t)0x08u)) | (( gfp_t)0x4000u) | (( gfp_t)0x10000u) | (( gfp_t)0x1000u) | (( gfp_t)0x200u) | ((&lt;br /&gt;
 gfp_t)0x400000u)), &amp;quot;GFP_TRANSHUGE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x20000u) | ((&lt;br /&gt;
 gfp_t)0x02u) | (( gfp_t)0x08u)), &amp;quot;GFP_HIGHUSER_MOVABLE&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u) | (( gfp_t)0x02u)), &amp;quot;GFP_HIGHUSER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( &lt;br /&gt;
 gfp_t)0x20000u)), &amp;quot;GFP_USER&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u) | (( gfp_t)0x80000u)), GFP_TEMPORARY&amp;quot;}, &lt;br /&gt;
 {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u) | (( gfp_t)0x80u)), &amp;quot;GFP_KERNEL&amp;quot;}, {(unsigned long)((( gfp_t)0x10u) | (( gfp_t)0x40u)), &lt;br /&gt;
 &amp;quot;GFP_NOFS&amp;quot;}, {(unsigned long)((( gfp_t)0x20u)), &amp;quot;GFP_ATOMIC&amp;quot;}, {(unsigned long)((( gfp_t)0x10u)), &amp;quot;GFP_NOIO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x20u), &amp;quot;GFP_HIGH&amp;quot;}, {(unsigned long)(( gfp_t)0x10u), &amp;quot;GFP_WAIT&amp;quot;}, {(unsigned long)(( gfp_t)0x40u), &amp;quot;GFP_IO&amp;quot;}, {(unsigned long)(( &lt;br /&gt;
 gfp_t)0x100u), &amp;quot;GFP_COLD&amp;quot;}, {(unsigned long)(( gfp_t)0x200u), &amp;quot;GFP_NOWARN&amp;quot;}, {(unsigned long)(( gfp_t)0x400u), &amp;quot;GFP_REPEAT&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x800u), &amp;quot;GFP_NOFAIL&amp;quot;}, {(unsigned long)(( gfp_t)0x1000u), &amp;quot;GFP_NORETRY&amp;quot;}, {(unsigned long)(( gfp_t)0x4000u), &amp;quot;GFP_COMP&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x8000u), &amp;quot;GFP_ZERO&amp;quot;}, {(unsigned long)(( gfp_t)0x10000u), &amp;quot;GFP_NOMEMALLOC&amp;quot;}, {(unsigned long)(( gfp_t)0x20000u), &lt;br /&gt;
 &amp;quot;GFP_HARDWALL&amp;quot;}, {(unsigned long)(( gfp_t)0x40000u), &amp;quot;GFP_THISNODE&amp;quot;}, {(unsigned long)(( gfp_t)0x80000u), &amp;quot;GFP_RECLAIMABLE&amp;quot;}, {(unsigned &lt;br /&gt;
 long)(( gfp_t)0x08u), &amp;quot;GFP_MOVABLE&amp;quot;}, {(unsigned long)(( gfp_t)0), &amp;quot;GFP_NOTRACK&amp;quot;}, {(unsigned long)(( gfp_t)0x400000u), &amp;quot;GFP_NO_KSWAPD&amp;quot;}, &lt;br /&gt;
 {(unsigned long)(( gfp_t)0x800000u), &amp;quot;GFP_OTHER_NODE&amp;quot;} ) : &amp;quot;GFP_NOWAIT&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8038</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8038"/>
		<updated>2012-11-15T04:08:00Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* The &amp;#039;trace events&amp;#039; subsystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system.  Listing out the contents of the &#039;events&#039; subdirectory, we see mainly another set of subdirectories:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls -al&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 drwxr-xr-x   19 root     root             0 Nov 14 23:19 block&lt;br /&gt;
 drwxr-xr-x   32 root     root             0 Nov 14 23:19 btrfs&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 drm&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 drwxr-xr-x   40 root     root             0 Nov 14 23:19 ext3&lt;br /&gt;
 drwxr-xr-x   79 root     root             0 Nov 14 23:19 ext4&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ftrace&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 hda&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_event&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 header_page&lt;br /&gt;
 drwxr-xr-x   25 root     root             0 Nov 14 23:19 i915&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 irq&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 jbd&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 jbd2&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 kmem&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 module&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 napi&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 net&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 oom&lt;br /&gt;
 drwxr-xr-x   12 root     root             0 Nov 14 23:19 power&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 printk&lt;br /&gt;
 drwxr-xr-x    8 root     root             0 Nov 14 23:19 random&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 raw_syscalls&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 rcu&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 rpm&lt;br /&gt;
 drwxr-xr-x   20 root     root             0 Nov 14 23:19 sched&lt;br /&gt;
 drwxr-xr-x    7 root     root             0 Nov 14 23:19 scsi&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 signal&lt;br /&gt;
 drwxr-xr-x    5 root     root             0 Nov 14 23:19 skb&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 sock&lt;br /&gt;
 drwxr-xr-x   10 root     root             0 Nov 14 23:19 sunrpc&lt;br /&gt;
 drwxr-xr-x  538 root     root             0 Nov 14 23:19 syscalls&lt;br /&gt;
 drwxr-xr-x    4 root     root             0 Nov 14 23:19 task&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 timer&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 udp&lt;br /&gt;
 drwxr-xr-x   21 root     root             0 Nov 14 23:19 vmscan&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Nov 14 23:19 vsyscall&lt;br /&gt;
 drwxr-xr-x    6 root     root             0 Nov 14 23:19 workqueue&lt;br /&gt;
 drwxr-xr-x   26 root     root             0 Nov 14 23:19 writeback&lt;br /&gt;
&lt;br /&gt;
Each one of these subdirectories corresponds to a &#039;subsystem&#039; and contains yet again more subdirectories, each one of those finally corresponding to a tracepoint.  For example, here are the contents of the &#039;kmem&#039; subsystem:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# cd kmem&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# ls -al&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   38 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kfree&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmalloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_alloc_node&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 kmem_cache_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_extfrag&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_alloc_zone_locked&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_free_batched&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 mm_page_pcpu_drain&lt;br /&gt;
&lt;br /&gt;
Let&#039;s see what&#039;s inside the subdirectory for a specific tracepoint, in this case the one for kmalloc:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem# cd kmalloc&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events/kmem/kmalloc# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Nov 14 23:19 .&lt;br /&gt;
 drwxr-xr-x   14 root     root             0 Nov 14 23:19 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Nov 14 23:19 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Nov 14 23:19 id&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8037</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8037"/>
		<updated>2012-11-14T23:56:23Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Basic ftrace usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
Also notice that there are various annotations on the left hand side of the display.  For example if the total time it took for a given function to execute is above a certain threshold, and exclamation point or plus sign appears on the left hand side.  Please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation] for details on all these fields.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8036</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8036"/>
		<updated>2012-11-14T23:51:42Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Basic ftrace usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
As you can see, the function_graph display is much easier to follow.  Also note that in addition to the function calls and associated braces, other events such as scheduler events are displayed in context.  In fact, you can freely include any tracepoint available in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#The_.27trace_events.27_subsystem trace events subsystem] described in the next section by simply enabling those events, and they&#039;ll appear in context in the function graph display.  Quite a powerful tool for understanding kernel dynamics.&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8035</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8035"/>
		<updated>2012-11-14T23:46:03Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Basic ftrace usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat trace | less&lt;br /&gt;
 &lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8034</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8034"/>
		<updated>2012-11-14T23:44:27Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Basic ftrace usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
  tracer: function_graph&lt;br /&gt;
 &lt;br /&gt;
  CPU  DURATION                  FUNCTION CALLS&lt;br /&gt;
  |     |   |                     |   |   |   |&lt;br /&gt;
 7)   0.046 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.043 us    |      pick_next_task_stop();&lt;br /&gt;
 7)   0.042 us    |      pick_next_task_rt();&lt;br /&gt;
 7)   0.032 us    |      pick_next_task_fair();&lt;br /&gt;
 7)   0.030 us    |      pick_next_task_idle();&lt;br /&gt;
 7)               |      _raw_spin_unlock_irq() {&lt;br /&gt;
 7)   0.033 us    |        sub_preempt_count();&lt;br /&gt;
 7)   0.258 us    |      }&lt;br /&gt;
 7)   0.032 us    |      sub_preempt_count();&lt;br /&gt;
 7) + 13.341 us   |    } /* __schedule */&lt;br /&gt;
 7)   0.095 us    |  } /* sub_preempt_count */&lt;br /&gt;
 7)               |  schedule() {&lt;br /&gt;
 7)               |    __schedule() {&lt;br /&gt;
 7)   0.060 us    |      add_preempt_count();&lt;br /&gt;
 7)   0.044 us    |      rcu_note_context_switch();&lt;br /&gt;
 7)               |      _raw_spin_lock_irq() {&lt;br /&gt;
 7)   0.033 us    |        add_preempt_count();&lt;br /&gt;
 7)   0.247 us    |      }&lt;br /&gt;
 7)               |      idle_balance() {&lt;br /&gt;
 7)               |        _raw_spin_unlock() {&lt;br /&gt;
 7)   0.031 us    |          sub_preempt_count();&lt;br /&gt;
 7)   0.246 us    |        }&lt;br /&gt;
 7)               |        update_shares() {&lt;br /&gt;
 7)   0.030 us    |          __rcu_read_lock();&lt;br /&gt;
 7)   0.029 us    |          __rcu_read_unlock();&lt;br /&gt;
 7)   0.484 us    |        }&lt;br /&gt;
 7)   0.030 us    |        __rcu_read_lock();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 7)   0.029 us    |            idle_cpu();&lt;br /&gt;
 7)   0.035 us    |            idle_cpu();&lt;br /&gt;
 7)   0.906 us    |          }&lt;br /&gt;
 7)   1.141 us    |        }&lt;br /&gt;
 7)   0.022 us    |        msecs_to_jiffies();&lt;br /&gt;
 7)               |        load_balance() {&lt;br /&gt;
 7)               |          find_busiest_group() {&lt;br /&gt;
 7)   0.031 us    |            idle_cpu();&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 4)   0.062 us    |        msecs_to_jiffies();&lt;br /&gt;
 4)   0.062 us    |        __rcu_read_unlock();&lt;br /&gt;
 4)               |        _raw_spin_lock() {&lt;br /&gt;
 4)   0.073 us    |          add_preempt_count();&lt;br /&gt;
 4)   0.562 us    |        }&lt;br /&gt;
 4) + 17.452 us   |      }&lt;br /&gt;
 4)   0.108 us    |      put_prev_task_fair();&lt;br /&gt;
 4)   0.102 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.084 us    |      pick_next_task_stop();&lt;br /&gt;
 4)   0.075 us    |      pick_next_task_rt();&lt;br /&gt;
 4)   0.062 us    |      pick_next_task_fair();&lt;br /&gt;
 4)   0.066 us    |      pick_next_task_idle();&lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 4)   kworker-74   =&amp;gt;    &amp;lt;idle&amp;gt;-0   &lt;br /&gt;
 ------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
 4)               |      finish_task_switch() {&lt;br /&gt;
 4)               |        _raw_spin_unlock_irq() {&lt;br /&gt;
 4)   0.100 us    |          sub_preempt_count();&lt;br /&gt;
 4)   0.582 us    |        }&lt;br /&gt;
 4)   1.105 us    |      }&lt;br /&gt;
 4)   0.088 us    |      sub_preempt_count();&lt;br /&gt;
 4) ! 100.066 us  |    }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
 3)   0.083 us    |    fget_light();&lt;br /&gt;
 3)               |    security_file_ioctl() {&lt;br /&gt;
 3)   0.066 us    |      cap_file_ioctl();&lt;br /&gt;
 3)   0.562 us    |    }&lt;br /&gt;
 3)               |    do_vfs_ioctl() {&lt;br /&gt;
 3)               |      drm_ioctl() {&lt;br /&gt;
 3)   0.075 us    |        drm_ut_debug_printk();&lt;br /&gt;
 3)               |        i915_gem_pwrite_ioctl() {&lt;br /&gt;
 3)               |          i915_mutex_lock_interruptible() {&lt;br /&gt;
 3)   0.070 us    |            mutex_lock_interruptible();&lt;br /&gt;
 3)   0.570 us    |          }&lt;br /&gt;
 3)               |          drm_gem_object_lookup() {&lt;br /&gt;
 3)               |            _raw_spin_lock() {&lt;br /&gt;
 3)   0.080 us    |              add_preempt_count();&lt;br /&gt;
 3)   0.620 us    |            }&lt;br /&gt;
 3)               |            _raw_spin_unlock() {&lt;br /&gt;
 3)   0.085 us    |              sub_preempt_count();&lt;br /&gt;
 3)   0.562 us    |            }&lt;br /&gt;
 3)   2.149 us    |          }&lt;br /&gt;
 3)   0.133 us    |          i915_gem_object_pin();&lt;br /&gt;
 3)               |          i915_gem_object_set_to_gtt_domain() {&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_flush_gpu_write_domain();&lt;br /&gt;
 3)   0.065 us    |            i915_gem_object_wait_rendering();&lt;br /&gt;
 3)   0.062 us    |            i915_gem_object_flush_cpu_write_domain();&lt;br /&gt;
 3)   1.612 us    |          }&lt;br /&gt;
 3)               |          i915_gem_object_put_fence() {&lt;br /&gt;
 3)   0.097 us    |            i915_gem_object_flush_fence.constprop.36();&lt;br /&gt;
 3)   0.645 us    |          }&lt;br /&gt;
 3)   0.070 us    |          add_preempt_count();&lt;br /&gt;
 3)   0.070 us    |          sub_preempt_count();&lt;br /&gt;
 3)   0.073 us    |          i915_gem_object_unpin();&lt;br /&gt;
 3)   0.068 us    |          mutex_unlock();&lt;br /&gt;
 3)   9.924 us    |        }&lt;br /&gt;
 3) + 11.236 us   |      }&lt;br /&gt;
 3) + 11.770 us   |    }&lt;br /&gt;
 3) + 13.784 us   |  }&lt;br /&gt;
 3)               |  sys_ioctl() {&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8033</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8033"/>
		<updated>2012-11-14T23:35:55Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Basic ftrace usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
Each line in the trace above shows what was happening in the kernel on a given cpu, to the level of detail of function calls.  Each entry shows the function called, followed by its caller (after the arrow).&lt;br /&gt;
&lt;br /&gt;
The function tracer gives you an extremely detailed idea of what the kernel was doing at the point in time the trace was taken, and is a great way to learn about how the kernel code works in a dynamic sense.&lt;br /&gt;
&lt;br /&gt;
It is a little more difficult to follow the call chains than it needs to be - luckily there&#039;s a variant of the function tracer that displays the callchains explicitly, called the &#039;function_graph&#039; tracer:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8032</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8032"/>
		<updated>2012-11-14T23:27:32Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Basic ftrace usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
 # tracer: function&lt;br /&gt;
 #&lt;br /&gt;
 # entries-in-buffer/entries-written: 310629/766471   #P:8&lt;br /&gt;
 #&lt;br /&gt;
 #                              _-----=&amp;gt; irqs-off&lt;br /&gt;
 #                             / _----=&amp;gt; need-resched&lt;br /&gt;
 #                            | / _---=&amp;gt; hardirq/softirq&lt;br /&gt;
 #                            || / _--=&amp;gt; preempt-depth&lt;br /&gt;
 #                            ||| /     delay&lt;br /&gt;
 #           TASK-PID   CPU#  ||||    TIMESTAMP  FUNCTION&lt;br /&gt;
 #              | |       |   ||||       |         |&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867169: ktime_get_real &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867170: getnstimeofday &amp;lt;-ktime_get_real&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timeval &amp;lt;-intel_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867171: ns_to_timespec &amp;lt;-ns_to_timeval&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: smp_apic_timer_interrupt &amp;lt;-apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: native_apic_mem_write &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: irq_enter &amp;lt;-smp_apic_timer_interrupt&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867172: rcu_irq_enter &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: rcu_idle_exit_common.isra.33 &amp;lt;-rcu_irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: local_bh_disable &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d..1   470.867173: add_preempt_count &amp;lt;-local_bh_disable&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_idle &amp;lt;-irq_enter&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_check_oneshot_broadcast &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: ktime_get &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867174: tick_nohz_stop_idle &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: update_ts_time_stats &amp;lt;-tick_nohz_stop_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: nr_iowait_cpu &amp;lt;-update_ts_time_stats&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: tick_do_update_jiffies64 &amp;lt;-tick_check_idle&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867175: _raw_spin_lock &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s1   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: do_timer &amp;lt;-tick_do_update_jiffies64&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: _raw_spin_lock &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s2   470.867176: add_preempt_count &amp;lt;-_raw_spin_lock&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: ntp_tick_length &amp;lt;-do_timer&lt;br /&gt;
          &amp;lt;idle&amp;gt;-0     [004] d.s3   470.867177: _raw_spin_lock_irqsave &amp;lt;-ntp_tick_length&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
          .&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8006</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8006"/>
		<updated>2012-11-14T16:40:12Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
The man pages in text form, along with some other files, such as a a set of examples, can be found in the &#039;perf&#039; directory of the kernel tree:&lt;br /&gt;
 tools/perf/Documentation&lt;br /&gt;
&lt;br /&gt;
There&#039;s also a nice perf tutorial on the perf wiki that goes into more detail than we do here in certain areas: [https://perf.wiki.kernel.org/index.php/Tutorial Perf Tutorial]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8005</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8005"/>
		<updated>2012-11-14T16:31:43Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
There&#039;s more detailed documentation kernelshark usage here: [http://rostedt.homelinux.com/kernelshark/ KernelShark]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8004</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8004"/>
		<updated>2012-11-14T16:28:04Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
There are a nice series of articles on using ftrace and trace-cmd at LWN:&lt;br /&gt;
&lt;br /&gt;
*[http://lwn.net/Articles/365835/ Debugging the kernel using Ftrace - part 1]&lt;br /&gt;
*[http://lwn.net/Articles/366796/ Debugging the kernel using Ftrace - part 2]&lt;br /&gt;
*[https://lwn.net/Articles/410200/ trace-cmd: A front-end for Ftrace]&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8003</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8003"/>
		<updated>2012-11-14T16:07:48Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Basic Usage (with examples) for each of the Yocto Tracing Tools */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8002</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8002"/>
		<updated>2012-11-14T15:55:07Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Tracing and Profiling in Yocto */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine application and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
	<entry>
		<id>https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8001</id>
		<title>Tracing and Profiling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yoctoproject.org/wiki/index.php?title=Tracing_and_Profiling&amp;diff=8001"/>
		<updated>2012-11-14T15:53:18Z</updated>

		<summary type="html">&lt;p&gt;Tzanussi: /* Tracing and Profiling in Yocto */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Tracing and Profiling in Yocto ==&lt;br /&gt;
&lt;br /&gt;
Yocto bundles a number of tracing and profiling tools - this &#039;HOWTO&#039; describes their basic usage and shows by example how to make use of them to examine real-world workloads and system behavior.&lt;br /&gt;
&lt;br /&gt;
The tools presented are for the most part completely open-ended and have quite good and/or extensive documentation of their own which can be used to solve just about any problem you might come across in Linux.  Each section that describes a particular tool has links to that tool&#039;s documentation and website.&lt;br /&gt;
&lt;br /&gt;
The purpose of this &#039;HOWTO&#039; is to present a set of common and generally useful tracing and profiling idioms along with their application (as appropriate) to each tool, in the context of a general-purpose &#039;drill-down&#039; methodology that can be applied to solving a large number (90%?) of problems.  For help with more advanced usages and problems, please see the documentation and/or websites listed for each tool.&lt;br /&gt;
&lt;br /&gt;
The final section of this &#039;HOWTO&#039; is a collection of [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Real-world_Examples real-world examples] which we&#039;ll be continually adding to as we solve more problems using the tools - feel free to add your own examples to the list! &lt;br /&gt;
&lt;br /&gt;
==== General Setup ====&lt;br /&gt;
Most of the tools are available only in &#039;sdk&#039; images or in images built after adding &#039;tools-profile&#039; to your local.conf.  So, in order to be able to access all of the tools described here, please first build and boot an &#039;sdk&#039; image e.g.&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato-sdk&lt;br /&gt;
&lt;br /&gt;
or alternatively by adding &#039;tools-profile&#039; to the EXTRA_IMAGE_FEATURES line in your local.conf:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you use the &#039;tools-profile&#039; method, you don&#039;t need to build an sdk image - the tracing and profiling tools will be included in non-sdk images as well e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ bitbake core-image-sato&lt;br /&gt;
&lt;br /&gt;
NOTES:&lt;br /&gt;
&lt;br /&gt;
By default, the Yocto build system strips symbols from the binaries it packages, which makes it difficult to use some of the tools.&lt;br /&gt;
&lt;br /&gt;
You can prevent that by putting the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above setting will noticeably increase the size of your image.&lt;br /&gt;
&lt;br /&gt;
If you&#039;ve already build a stripped image, you can generate debug packages (xxx-dbg) which you can manually install as needed.&lt;br /&gt;
&lt;br /&gt;
To generate debug info for packages, you can add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the right type of debuginfo, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
== Overall Architecture of the Linux Tracing and Profiling Tools ==&lt;br /&gt;
&lt;br /&gt;
It may seem surprising to see a section covering an &#039;overall architecture&#039; for what seems to be a random collection of tracing tools that together make up the Linux tracing and profiling space.  The fact is, however, that in recent years this seemingly disparate set of tools has started to converge on a &#039;core&#039; set of underlying mechanisms:&lt;br /&gt;
&lt;br /&gt;
* static tracepoints&lt;br /&gt;
* dynamic tracepoints&lt;br /&gt;
** kprobes&lt;br /&gt;
** uprobes&lt;br /&gt;
* the perf_events subsystem&lt;br /&gt;
* debugfs&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Rather than enumerating here how each tool makes use of these common mechanisms, textboxes&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   like this will make note of the specific usages in each tool as they come up in the course&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   of the text.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Basic Usage (with examples) for each of the Yocto Tracing Tools  ==&lt;br /&gt;
&lt;br /&gt;
=== perf ===&lt;br /&gt;
&lt;br /&gt;
The &#039;perf&#039; tool is the profiling and tracing tool that comes bundled with the Linux kernel.&lt;br /&gt;
&lt;br /&gt;
Don&#039;t let the fact that it&#039;s part of the kernel fool you into thinking that it&#039;s only for tracing and profiling the kernel - you can indeed use it to trace and profile just the kernel , but you can also use it to profile specific applications separately (with or without kernel context), and you can also use it to trace and profile the kernel and all applications on the system simultaneously to gain a system-wide view of what&#039;s going on in the system.&lt;br /&gt;
&lt;br /&gt;
In many ways, it aims to be a superset of all the tracing and profiling tools available in Linux today, including all the other tools covered in this HOWTO.  The past couple of years have seen perf subsume a lot of the functionality of those other tools, and at the same time those other tools have removed large portions of their previous functionality and replaced it with calls to the equivalent functionality now implemented by the perf subsystem.  Extrapolation suggests that at some point those other tools will simply become completely redundant and go away; until then, we&#039;ll cover those other tools in these pages and in many cases show how the same things can be accomplished in perf and the other tools when it seems useful to do so.&lt;br /&gt;
&lt;br /&gt;
The coverage below details some of the most common ways you&#039;ll likely want to apply the tool; full documentation can be found either within the tool itself or in the man pages:&lt;br /&gt;
&lt;br /&gt;
[http://linux.die.net/man/1/perf perf(1)]&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
In particular, you&#039;ll get the most mileage out of perf if you profile an image built with INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot; in your local.conf.&lt;br /&gt;
&lt;br /&gt;
perf runs on the target system for the most part.  You can archive profile data and copy it to the host for analysis, but for the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running the perf commands on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
The perf tool is pretty much self-documenting.  To remind yourself of the available commands, simply type &#039;perf&#039;, which will show you basic usage along with the available perf subcommands:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf&lt;br /&gt;
 &lt;br /&gt;
 usage: perf [--version] [--help] COMMAND [ARGS]&lt;br /&gt;
 &lt;br /&gt;
 The most commonly used perf commands are:&lt;br /&gt;
   annotate        Read perf.data (created by perf record) and display annotated code&lt;br /&gt;
   archive         Create archive with object files with build-ids found in perf.data file&lt;br /&gt;
   bench           General framework for benchmark suites&lt;br /&gt;
   buildid-cache   Manage build-id cache.&lt;br /&gt;
   buildid-list    List the buildids in a perf.data file&lt;br /&gt;
   diff            Read two perf.data files and display the differential profile&lt;br /&gt;
   evlist          List the event names in a perf.data file&lt;br /&gt;
   inject          Filter to augment the events stream with additional information&lt;br /&gt;
   kmem            Tool to trace/measure kernel memory(slab) properties&lt;br /&gt;
   kvm             Tool to trace/measure kvm guest os&lt;br /&gt;
   list            List all symbolic event types&lt;br /&gt;
   lock            Analyze lock events&lt;br /&gt;
   probe           Define new dynamic tracepoints&lt;br /&gt;
   record          Run a command and record its profile into perf.data&lt;br /&gt;
   report          Read perf.data (created by perf record) and display the profile&lt;br /&gt;
   sched           Tool to trace/measure scheduler properties (latencies)&lt;br /&gt;
   script          Read perf.data (created by perf record) and display trace output&lt;br /&gt;
   stat            Run a command and gather performance counter statistics&lt;br /&gt;
   test            Runs sanity tests.&lt;br /&gt;
   timechart       Tool to visualize total system behavior during a workload&lt;br /&gt;
   top             System profiling tool.&lt;br /&gt;
 &lt;br /&gt;
 See &#039;perf help COMMAND&#039; for more information on a specific command.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic profiling =====&lt;br /&gt;
&lt;br /&gt;
As a simple test case, we&#039;ll profile the &#039;wget&#039; of a fairly large file, 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&#039;s implemented as part of busybox, so the methods we use to analyze it can be used in a very similar way to the whole host of supported busybox applets in Yocto.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
The quickest and easiest way to get some basic overall data about what&#039;s going on for a particular workload it to profile it using &#039;perf stat&#039;.  &#039;perf stat&#039; basically profiles using a few default counters and displays the summed counts at the end of the run: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
       4597.223902 task-clock                #    0.077 CPUs utilized          &lt;br /&gt;
             23568 context-switches          #    0.005 M/sec                  &lt;br /&gt;
                68 CPU-migrations            #    0.015 K/sec                  &lt;br /&gt;
               241 page-faults               #    0.052 K/sec                  &lt;br /&gt;
        3045817293 cycles                    #    0.663 GHz                    &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-frontend &lt;br /&gt;
   &amp;lt;not supported&amp;gt; stalled-cycles-backend  &lt;br /&gt;
         858909167 instructions              #    0.28  insns per cycle        &lt;br /&gt;
         165441165 branches                  #   35.987 M/sec                  &lt;br /&gt;
          19550329 branch-misses             #   11.82% of all branches        &lt;br /&gt;
 &lt;br /&gt;
      59.836627620 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Many times such a simple-minded test doesn&#039;t yield much of interest, but sometimes it does (see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Yocto_Bug_3049 Real-world Yocto bug (slow loop-mounted write speed])).&lt;br /&gt;
&lt;br /&gt;
Also, note that &#039;perf stat&#039; isn&#039;t restricted to a fixed set of counters - basically any event listed in the output of &#039;perf list&#039; can be tallied by &#039;perf stat&#039;.  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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e kmem:* -e cache-references -e cache-misses wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |***************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 &lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
              5566 kmem:kmalloc                                                &lt;br /&gt;
            125517 kmem:kmem_cache_alloc                                       &lt;br /&gt;
                 0 kmem:kmalloc_node                                           &lt;br /&gt;
                 0 kmem:kmem_cache_alloc_node                                   &lt;br /&gt;
             34401 kmem:kfree                                                  &lt;br /&gt;
             69920 kmem:kmem_cache_free                                        &lt;br /&gt;
               133 kmem:mm_page_free                                           &lt;br /&gt;
                41 kmem:mm_page_free_batched                                   &lt;br /&gt;
             11502 kmem:mm_page_alloc                                          &lt;br /&gt;
             11375 kmem:mm_page_alloc_zone_locked                                   &lt;br /&gt;
                 0 kmem:mm_page_pcpu_drain                                     &lt;br /&gt;
                 0 kmem:mm_page_alloc_extfrag                                   &lt;br /&gt;
          66848602 cache-references                                            &lt;br /&gt;
           2917740 cache-misses              #    4.365 % of all cache refs    &lt;br /&gt;
 &lt;br /&gt;
      44.831023415 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
So &#039;perf stat&#039; gives us a nice easy way to get a quick overview of what might be happening for a set of events, but normally we&#039;d need a little more detail in order to understand what&#039;s going on in a way that we can act on in a useful way.&lt;br /&gt;
&lt;br /&gt;
To dive down into a next level of detail, we can use &#039;perf record&#039;/&#039;perf report&#039; which will collect profiling data and present it to use using an interactive text-based UI (or simply as text if we specify --stdio to &#039;perf report&#039;).&lt;br /&gt;
&lt;br /&gt;
As our first attempt at profiling this workload, we&#039;ll simply run &#039;perf record&#039;, handing it the workload we want to profile (everything after &#039;perf record&#039; and any perf options we hand it - here none - will be executedin a new shell).   perf collects samples until the process exits and records them in a file named &#039;perf.data&#039; in the current working directory.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 &lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.176 MB perf.data (~7700 samples) ]&lt;br /&gt;
&lt;br /&gt;
To see the results in a &#039;text-based UI&#039; (tui), simply run &#039;perf report&#039;, which will read the perf.data file in the current working directory and display the results in an interactive UI:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-flat-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot displays a &#039;flat&#039; profile, one entry for each &#039;bucket&#039; corresponding to the functions that were profiled during the profiling run, ordered from the most popular to the least (perf has options to sort in various orders and keys as well as display entries only above a certain threshold and so on - see the perf documentation for details).  Note that this includes both userspace functions (entries containing a [.]) and kernel functions accounted to the process (entries containing a [k]).  (perf has command-line modifiers that can be used to restrict the profiling to kernel or userspace, among others).&lt;br /&gt;
&lt;br /&gt;
Notice also that the above report shows an entry for &#039;busybox&#039;, which is the executable that implements &#039;wget&#039; in Yocto, but that instead of a useful function name in that entry, it displays an not-so-friendly hex value instead.  The steps below will show how to fix that problem.&lt;br /&gt;
&lt;br /&gt;
Before we do that, however, let&#039;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&#039;ll add the -g option, which will record not just the address of a sampled function, but the entire callchain to the sampled function as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |************************************************| 41727k  0:00:00 ETA&lt;br /&gt;
 [ perf record: Woken up 3 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.652 MB perf.data (~28476 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf report&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Using the callgraph view, we can actually see not only which functions took the most time, but we can also see a summary of how those functions were called and learn something about how the program interacts with the kernel in the process.&lt;br /&gt;
&lt;br /&gt;
Notice that each entry in the above screenshot now contains a &#039;+&#039; on the left-hand side.  This means that we can expand the entry and drill down into the callchains that feed into that entry.  Pressing &#039;enter&#039; on any one of them will expand the callchain (you can also press &#039;E&#039; to expand them all at the same time or &#039;C&#039; to collapse them all).&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;ve toggled the __copy_to_user_ll() entry and several subnodes all the way down.  This lets us see which callchains contributed to the profiled __copy_to_user_ll() function which contributed 1.77% to the total profile.&lt;br /&gt;
&lt;br /&gt;
As a bit of background explanation for these callchains, think about what happens at a high level when you run wget to get a file out on the network.  Basically what happens is that the data comes into the kernel via the network connection (socket) and is passed to the userspace program &#039;wget&#039; (which is actually a part of busybox, but that&#039;s not important for now), which takes the buffers the kernel passes to it and writes it to a disk file to save it.&lt;br /&gt;
&lt;br /&gt;
The part of this process that we&#039;re looking at in the above call stacks is the part where the kernel passes the data it&#039;s read from the socket down to wget i.e. a copy-to-user.&lt;br /&gt;
&lt;br /&gt;
Notice also that here there&#039;s also a case where the a hex value is displayed in the callstack, here in the expanded sys_clock_gettime() function.  Later we&#039;ll see it resolve to a userspace function call in busybox.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-from-user-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
The above screenshot shows the other half of the journey for the data - from the wget program&#039;s userspace buffers to disk.  To get the buffers to disk, the wget program issues a write(2), which does a copy-from-user to the kernel, which then takes care via some circuitous path (probably also present somewhere in the profile data), to get it safely to disk.&lt;br /&gt;
&lt;br /&gt;
Now that we&#039;ve seen the basic layout of the profile data and the basics of how to extract useful information out of it, let&#039;s get back to the task at hand and see if we can get some basic idea about where the time is spent in the program we&#039;re profiling, wget.  Remember that wget is actually implemented as an applet in busybox, so while the process name is &#039;wget&#039;, the executable we&#039;re actually interested in is busybox.  So let&#039;s expand the first entry containing busybox:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-expanded-stripped.gif]]&lt;br /&gt;
&lt;br /&gt;
Again, before we expanded we saw that the function was labeled with a hex value instead of a symbol as with most of the kernel entries.  Expanding the busybox entry doesn&#039;t make it any better.&lt;br /&gt;
&lt;br /&gt;
The problem is that perf can&#039;t find the symbol information for the busybox binary, which is actually stripped out by the Yocto build system.&lt;br /&gt;
&lt;br /&gt;
One way around that is to put the following in your local.conf when you build the image:&lt;br /&gt;
&lt;br /&gt;
 INHIBIT_PACKAGE_STRIP = &amp;quot;1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
However, we already have an image with the binaries stripped, so what can we do to get perf to resolve the symbols?  Basically we need to install the debuginfo for the busybox package.&lt;br /&gt;
&lt;br /&gt;
To generate the debug info for the packages in the image, we can to add dbg-pkgs to EXTRA_IMAGE_FEATURES in local.conf.  For example:&lt;br /&gt;
&lt;br /&gt;
 EXTRA_IMAGE_FEATURES = &amp;quot;debug-tweaks tools-profile dbg-pkgs&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Additionally, in order to generate the type of debuginfo that perf understands, we also need to add the following to local.conf:&lt;br /&gt;
&lt;br /&gt;
 PACKAGE_DEBUG_SPLIT_STYLE = &#039;debug-file-directory&#039;&lt;br /&gt;
&lt;br /&gt;
Once we&#039;ve done that, we can install the debuginfo 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:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada core2]$ scp /home/trz/yocto/crownbay-tracing-dbg/build/tmp/deploy/rpm/core2/busybox-dbg-1.20.2-r2.core2.rpm root@192.168.1.31:&lt;br /&gt;
 root@192.168.1.31&#039;s password:&lt;br /&gt;
 busybox-dbg-1.20.2-r2.core2.rpm                     100% 1826KB   1.8MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Now install the debug rpm on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rpm -i busybox-dbg-1.20.2-r2.core2.rpm&lt;br /&gt;
&lt;br /&gt;
Now that the debuginfo is installed, we see that the busybox entries now display their functions symbolically:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
If we expand one of the entries and press &#039;enter&#039; on a leaf node, we&#039;re presented with a menu of actions we can take to get more information related to that entry:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
One of these actions allows us to show a view that displays a busybox-centric view of the profiled functions (in this case we&#039;ve also expanded all the nodes using the &#039;E&#039; key):&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-dso-zoom.gif]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can see that now that the busybox debuginfo is installed, the previously unresolved symbol in the sys_clock_gettime() entry mentioned previously is now resolved, and shows that the sys_clock_gettime system call that was the source of 6.75% of the copy-to-user overhead was initiated by the handle_input() busybox function:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-g-copy-to-user-expanded-debuginfo.gif]]&lt;br /&gt;
&lt;br /&gt;
At the lowest level of detail, we can dive down to the assembly level and see which instructions caused the most overhead in a function.  Pressing &#039;enter&#039; on the &#039;udhcpc_main&#039; function, we&#039;re again presented with a menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-menu.gif]]&lt;br /&gt;
&lt;br /&gt;
Selecting &#039;Annotate udhcpc_main&#039;, we get a detailed listing of percentages by instruction for the udhcpc_main function.  From the display, we can see that over 50% of the time spent in this function is taken up by a couple tests and the move of a constant (1) to a register:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-wget-busybox-annotate-udhcpc.gif]]&lt;br /&gt;
&lt;br /&gt;
As a segue into tracing, let&#039;s try another profile using a different counter, something other than the default &#039;cycles&#039;.&lt;br /&gt;
&lt;br /&gt;
The tracing and profiling infrastructure in Linux has become unified in a way that allows us to use the same tool with a completely different set of counters, not just the standard hardware counters that traditionally tools have had to restrict themselves to (of course the traditional tools can also make use of the expanded possibilities now available to them, and in some cases have, as mentioned previously).&lt;br /&gt;
&lt;br /&gt;
We can get a list of the available events that can be used to profile a workload via &#039;perf list&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf list&lt;br /&gt;
 &lt;br /&gt;
 List of pre-defined events (to be used in -e):&lt;br /&gt;
  cpu-cycles OR cycles                               [Hardware event]&lt;br /&gt;
  stalled-cycles-frontend OR idle-cycles-frontend    [Hardware event]&lt;br /&gt;
  stalled-cycles-backend OR idle-cycles-backend      [Hardware event]&lt;br /&gt;
  instructions                                       [Hardware event]&lt;br /&gt;
  cache-references                                   [Hardware event]&lt;br /&gt;
  cache-misses                                       [Hardware event]&lt;br /&gt;
  branch-instructions OR branches                    [Hardware event]&lt;br /&gt;
  branch-misses                                      [Hardware event]&lt;br /&gt;
  bus-cycles                                         [Hardware event]&lt;br /&gt;
  ref-cycles                                         [Hardware event]&lt;br /&gt;
 &lt;br /&gt;
  cpu-clock                                          [Software event]&lt;br /&gt;
  task-clock                                         [Software event]&lt;br /&gt;
  page-faults OR faults                              [Software event]&lt;br /&gt;
  minor-faults                                       [Software event]&lt;br /&gt;
  major-faults                                       [Software event]&lt;br /&gt;
  context-switches OR cs                             [Software event]&lt;br /&gt;
  cpu-migrations OR migrations                       [Software event]&lt;br /&gt;
  alignment-faults                                   [Software event]&lt;br /&gt;
  emulation-faults                                   [Software event]&lt;br /&gt;
 &lt;br /&gt;
  L1-dcache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-dcache-load-misses                              [Hardware cache event]&lt;br /&gt;
  L1-dcache-prefetch-misses                          [Hardware cache event]&lt;br /&gt;
  L1-icache-loads                                    [Hardware cache event]&lt;br /&gt;
  L1-icache-load-misses                              [Hardware cache event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  rNNN                                               [Raw hardware event descriptor]&lt;br /&gt;
  cpu/t1=v1[,t2=v2,t3 ...]/modifier                  [Raw hardware event descriptor]&lt;br /&gt;
   (see &#039;perf list --help&#039; on how to encode it)&lt;br /&gt;
 &lt;br /&gt;
  mem:&amp;lt;addr&amp;gt;[:access]                                [Hardware breakpoint]&lt;br /&gt;
 &lt;br /&gt;
  sunrpc:rpc_call_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_bind_status                             [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_connect_status                          [Tracepoint event]&lt;br /&gt;
  sunrpc:rpc_task_begin                              [Tracepoint event]&lt;br /&gt;
  skb:kfree_skb                                      [Tracepoint event]&lt;br /&gt;
  skb:consume_skb                                    [Tracepoint event]&lt;br /&gt;
  skb:skb_copy_datagram_iovec                        [Tracepoint event]&lt;br /&gt;
  net:net_dev_xmit                                   [Tracepoint event]&lt;br /&gt;
  net:net_dev_queue                                  [Tracepoint event]&lt;br /&gt;
  net:netif_receive_skb                              [Tracepoint event]&lt;br /&gt;
  net:netif_rx                                       [Tracepoint event]&lt;br /&gt;
  napi:napi_poll                                     [Tracepoint event]&lt;br /&gt;
  sock:sock_rcvqueue_full                            [Tracepoint event]&lt;br /&gt;
  sock:sock_exceed_buf_limit                         [Tracepoint event]&lt;br /&gt;
  udp:udp_fail_queue_rcv_skb                         [Tracepoint event]&lt;br /&gt;
  hda:hda_send_cmd                                   [Tracepoint event]&lt;br /&gt;
  hda:hda_get_response                               [Tracepoint event]&lt;br /&gt;
  hda:hda_bus_reset                                  [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_start                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_dispatch_cmd_error                       [Tracepoint event]&lt;br /&gt;
  scsi:scsi_eh_wakeup                                [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event                               [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_queued                        [Tracepoint event]&lt;br /&gt;
  drm:drm_vblank_event_delivered                     [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes                              [Tracepoint event]&lt;br /&gt;
  random:mix_pool_bytes_nolock                       [Tracepoint event]&lt;br /&gt;
  random:credit_entropy_bits                         [Tracepoint event]&lt;br /&gt;
  gpio:gpio_direction                                [Tracepoint event]&lt;br /&gt;
  gpio:gpio_value                                    [Tracepoint event]&lt;br /&gt;
  block:block_rq_abort                               [Tracepoint event]&lt;br /&gt;
  block:block_rq_requeue                             [Tracepoint event]&lt;br /&gt;
  block:block_rq_issue                               [Tracepoint event]&lt;br /&gt;
  block:block_bio_bounce                             [Tracepoint event]&lt;br /&gt;
  block:block_bio_complete                           [Tracepoint event]&lt;br /&gt;
  block:block_bio_backmerge                          [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_wake_thread                    [Tracepoint event]&lt;br /&gt;
  writeback:writeback_wake_forker_thread             [Tracepoint event]&lt;br /&gt;
  writeback:writeback_bdi_register                   [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  writeback:writeback_single_inode_requeue           [Tracepoint event]&lt;br /&gt;
  writeback:writeback_single_inode                   [Tracepoint event]&lt;br /&gt;
  kmem:kmalloc                                       [Tracepoint event]&lt;br /&gt;
  kmem:kmem_cache_alloc                              [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc                                 [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_zone_locked                     [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_pcpu_drain                            [Tracepoint event]&lt;br /&gt;
  kmem:mm_page_alloc_extfrag                         [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_sleep                      [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_kswapd_wake                       [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_wakeup_kswapd                     [Tracepoint event]&lt;br /&gt;
  vmscan:mm_vmscan_direct_reclaim_begin              [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  module:module_get                                  [Tracepoint event]&lt;br /&gt;
  module:module_put                                  [Tracepoint event]&lt;br /&gt;
  module:module_request                              [Tracepoint event]&lt;br /&gt;
  sched:sched_kthread_stop                           [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup                                 [Tracepoint event]&lt;br /&gt;
  sched:sched_wakeup_new                             [Tracepoint event]&lt;br /&gt;
  sched:sched_process_fork                           [Tracepoint event]&lt;br /&gt;
  sched:sched_process_exec                           [Tracepoint event]&lt;br /&gt;
  sched:sched_stat_runtime                           [Tracepoint event]&lt;br /&gt;
  rcu:rcu_utilization                                [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_queue_work                     [Tracepoint event]&lt;br /&gt;
  workqueue:workqueue_execute_end                    [Tracepoint event]&lt;br /&gt;
  signal:signal_generate                             [Tracepoint event]&lt;br /&gt;
  signal:signal_deliver                              [Tracepoint event]&lt;br /&gt;
  timer:timer_init                                   [Tracepoint event]&lt;br /&gt;
  timer:timer_start                                  [Tracepoint event]&lt;br /&gt;
  timer:hrtimer_cancel                               [Tracepoint event]&lt;br /&gt;
  timer:itimer_state                                 [Tracepoint event]&lt;br /&gt;
  timer:itimer_expire                                [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_entry                              [Tracepoint event]&lt;br /&gt;
  irq:irq_handler_exit                               [Tracepoint event]&lt;br /&gt;
  irq:softirq_entry                                  [Tracepoint event]&lt;br /&gt;
  irq:softirq_exit                                   [Tracepoint event]&lt;br /&gt;
  irq:softirq_raise                                  [Tracepoint event]&lt;br /&gt;
  printk:console                                     [Tracepoint event]&lt;br /&gt;
  task:task_newtask                                  [Tracepoint event]&lt;br /&gt;
  task:task_rename                                   [Tracepoint event]&lt;br /&gt;
  syscalls:sys_enter_socketcall                      [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_socketcall                       [Tracepoint event]&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  syscalls:sys_enter_unshare                         [Tracepoint event]&lt;br /&gt;
  syscalls:sys_exit_unshare                          [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_enter                             [Tracepoint event]&lt;br /&gt;
  raw_syscalls:sys_exit                              [Tracepoint event]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of events defined by the trace event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   exposed by ftrace/tracecmd/kernelshark as files in /sys/kernel/debug/tracing/events,&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   by SystemTap as kernel.trace(&amp;quot;tracepoint_name&amp;quot;) and (partially) accessed by LTTng.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Only a subset of these would be of interest to us when looking at this workload, so let&#039;s choose the most likely subsystems (identified by the string before the colon in the Tracepoint events) and do a &#039;perf stat&#039; run using only those wildcarded subsystems:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf stat -e skb:* -e net:* -e napi:* -e sched:* -e workqueue:* -e irq:* -e syscalls:* wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Performance counter stats for &#039;wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&#039;:&lt;br /&gt;
 &lt;br /&gt;
             23323 skb:kfree_skb                                               &lt;br /&gt;
                 0 skb:consume_skb                                             &lt;br /&gt;
             49897 skb:skb_copy_datagram_iovec                                   &lt;br /&gt;
              6217 net:net_dev_xmit                                            &lt;br /&gt;
              6217 net:net_dev_queue                                           &lt;br /&gt;
              7962 net:netif_receive_skb                                       &lt;br /&gt;
                 2 net:netif_rx                                                &lt;br /&gt;
              8340 napi:napi_poll                                              &lt;br /&gt;
                 0 sched:sched_kthread_stop                                    &lt;br /&gt;
                 0 sched:sched_kthread_stop_ret                                   &lt;br /&gt;
              3749 sched:sched_wakeup                                          &lt;br /&gt;
                 0 sched:sched_wakeup_new                                      &lt;br /&gt;
                 0 sched:sched_switch                                          &lt;br /&gt;
                29 sched:sched_migrate_task                                    &lt;br /&gt;
                 0 sched:sched_process_free                                    &lt;br /&gt;
                 1 sched:sched_process_exit                                    &lt;br /&gt;
                 0 sched:sched_wait_task                                       &lt;br /&gt;
                 0 sched:sched_process_wait                                    &lt;br /&gt;
                 0 sched:sched_process_fork                                    &lt;br /&gt;
                 1 sched:sched_process_exec                                    &lt;br /&gt;
                 0 sched:sched_stat_wait                                       &lt;br /&gt;
     2106519415641 sched:sched_stat_sleep                                      &lt;br /&gt;
                 0 sched:sched_stat_iowait                                     &lt;br /&gt;
         147453613 sched:sched_stat_blocked                                    &lt;br /&gt;
       12903026955 sched:sched_stat_runtime                                    &lt;br /&gt;
                 0 sched:sched_pi_setprio                                      &lt;br /&gt;
              3574 workqueue:workqueue_queue_work                                   &lt;br /&gt;
              3574 workqueue:workqueue_activate_work                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_start                                   &lt;br /&gt;
                 0 workqueue:workqueue_execute_end                                   &lt;br /&gt;
             16631 irq:irq_handler_entry                                       &lt;br /&gt;
             16631 irq:irq_handler_exit                                        &lt;br /&gt;
             28521 irq:softirq_entry                                           &lt;br /&gt;
             28521 irq:softirq_exit                                            &lt;br /&gt;
             28728 irq:softirq_raise                                           &lt;br /&gt;
                 1 syscalls:sys_enter_sendmmsg                                   &lt;br /&gt;
                 1 syscalls:sys_exit_sendmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_enter_recvmmsg                                   &lt;br /&gt;
                 0 syscalls:sys_exit_recvmmsg                                   &lt;br /&gt;
                14 syscalls:sys_enter_socketcall                                   &lt;br /&gt;
                14 syscalls:sys_exit_socketcall                                   &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
             16965 syscalls:sys_enter_read                                     &lt;br /&gt;
             16965 syscalls:sys_exit_read                                      &lt;br /&gt;
             12854 syscalls:sys_enter_write                                    &lt;br /&gt;
             12854 syscalls:sys_exit_write                                     &lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
                   .&lt;br /&gt;
 &lt;br /&gt;
      58.029710972 seconds time elapsed&lt;br /&gt;
&lt;br /&gt;
Let&#039;s pick one of these tracepoints and tell perf to do a profile using it as the sampling event:&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# perf record -g -e sched:sched_wakeup wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
[[File:Sched-wakeup-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
The screenshot above shows the results of running a profile using sched:sched_switch tracepoint, which shows the relative costs of various paths to sched_wakeup (note that sched_wakeup is the name of the tracepoint - it&#039;s actually defined just inside ttwu_do_wakeup(), which accounts for the function name actually displayed in the profile:&lt;br /&gt;
&lt;br /&gt;
 /*&lt;br /&gt;
  * Mark the task runnable and perform wakeup-preemption.&lt;br /&gt;
  */&lt;br /&gt;
 static void&lt;br /&gt;
 ttwu_do_wakeup(struct rq *rq, struct task_struct *p, int wake_flags)&lt;br /&gt;
 {&lt;br /&gt;
  	trace_sched_wakeup(p, true);&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
         .&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
A couple of the more interesting callchains are expanded and displayed above, basically some network receive paths that presumably end up waking up wget (busybox) when network data is ready.&lt;br /&gt;
&lt;br /&gt;
Note that because tracepoints are normally used for tracing, the default sampling period for tracepoints is 1 i.e. for tracepoints perf will sample on every event occurrence (this can be changed using the -c option).  This is in contrast to hardware counters such as for example the default &#039;cycles&#039; hardware counter used for normal profiling, where sampling periods are much higher (in the thousands) because profiling should have as low an overhead as possible and sampling on every cycle would be prohibitively expensive.&lt;br /&gt;
&lt;br /&gt;
===== Using perf to do basic tracing =====&lt;br /&gt;
&lt;br /&gt;
Profiling is a great tool for solving many problems or for getting a high-level view of what&#039;s going on with a workload or across the system.  It is however by definition an approximation, as suggested by the most prominent word associated with it, &#039;sampling&#039;.  On the one hand, it allows a representative picture of what&#039;s going on in the system to be cheaply taken, but on the other hand, that cheapness limits its utility when that data suggests a need to &#039;dive down&#039; more deeply to discover what&#039;s really going on.  In such cases, the only way to see what&#039;s really going on is to be able to look at (or summarize more intelligently) the individual steps that go into the higher-level behavior exposed by the coarse-grained profiling data.&lt;br /&gt;
&lt;br /&gt;
As a concrete example, we can trace all the events we think might be applicable to our workload: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -e skb:* -e net:* -e napi:* -e sched:sched_switch -e sched:sched_wakeup -e irq:*&lt;br /&gt;
  -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write&lt;br /&gt;
  wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
&lt;br /&gt;
We can look at the raw trace output using &#039;perf script&#039; with no arguments: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
&lt;br /&gt;
            perf  1262 [000] 11624.857082: sys_exit_read: 0x0&lt;br /&gt;
            perf  1262 [000] 11624.857193: sched_wakeup: comm=migration/0 pid=6 prio=0 success=1 target_cpu=000&lt;br /&gt;
            wget  1262 [001] 11624.858021: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858074: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858081: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.858166: sys_enter_read: fd: 0x0003, buf: 0xbf82c940, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.858177: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.858878: kfree_skb: skbaddr=0xeb248d80 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.858945: kfree_skb: skbaddr=0xeb248000 protocol=0 location=0xc15a5308&lt;br /&gt;
            wget  1262 [001] 11624.859020: softirq_raise: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859076: softirq_entry: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859083: softirq_exit: vec=1 [action=TIMER]&lt;br /&gt;
            wget  1262 [001] 11624.859167: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859192: sys_exit_read: 0x1d7&lt;br /&gt;
            wget  1262 [001] 11624.859228: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859233: sys_exit_read: 0x0&lt;br /&gt;
            wget  1262 [001] 11624.859573: sys_enter_read: fd: 0x0003, buf: 0xbf82c580, count: 0x0200&lt;br /&gt;
            wget  1262 [001] 11624.859584: sys_exit_read: 0x200&lt;br /&gt;
            wget  1262 [001] 11624.859864: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859888: sys_exit_read: 0x400&lt;br /&gt;
            wget  1262 [001] 11624.859935: sys_enter_read: fd: 0x0003, buf: 0xb7720000, count: 0x0400&lt;br /&gt;
            wget  1262 [001] 11624.859944: sys_exit_read: 0x400&lt;br /&gt;
&lt;br /&gt;
This gives us a detailed timestamped sequence of events that occurred within the workload with respect to those events.&lt;br /&gt;
&lt;br /&gt;
In many ways, profiling can be viewed as a subset of tracing - theoretically, if you have a set of trace events that&#039;s sufficient to capture all the important aspects of a workload, you can derive any of the results or views that a profiling run can.&lt;br /&gt;
&lt;br /&gt;
Another aspect of traditional profiling is that while powerful in many ways, it&#039;s limited by the granularity of the underlying data.  Profiling tools offer various ways of sorting and presenting the sample data, which make it much more useful and amenable to user experimentation, but in the end it can&#039;t be used in an open-ended way to extract data that just isn&#039;t present as a consequence of the fact that conceptually, most of it has been thrown away.&lt;br /&gt;
&lt;br /&gt;
Full-blown detailed tracing data does however offer the opportunity to manipulate and present the information collected during a tracing run in an infinite variety of ways.&lt;br /&gt;
&lt;br /&gt;
Another way to look at it is that there are only so many ways that the &#039;primitive&#039; counters can be used on their own to generate interesting output; to get anything more complicated than simple counts requires some amount of additional logic, which is typically very specific to the problem at hand.  For example, if we wanted to make use of a &#039;counter&#039; that maps to the value of the time difference between when a process was scheduled to run on a processor and the time it actually ran, we wouldn&#039;t expect such a counter to exist on its own, but we could derive one called say &#039;wakeup_latency&#039; and use it to extract a useful view of that metric from trace data.   Likewise, we really can&#039;t figure out from standard profiling tools how much data every process on the system reads and writes, along with how many of those reads and writes fail completely.  If we have sufficient trace data, however, we could with the right tools easily extract and present that information, but we&#039;d need something other than pre-canned profiling tools to do that. &lt;br /&gt;
&lt;br /&gt;
Luckily, there is general-purpose way to handle such needs, called &#039;programming languages&#039;.  Making programming languages easily available to apply to such problems given the specific format of data is called a &#039;programming language binding&#039; for that data and language.  Perf supports two programming language bindings, one for Python and one for Perl.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Language bindings for manipulating and aggregating trace data are of course not a new&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   idea.  One of the first projects to do this was IBM&#039;s DProbes dpcc compiler, an ANSI C&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   compiler which targeted a low-level assembly language running on an in-kernel interpreter&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   on the target system.  This is exactly analagous to what Sun&#039;s DTrace did, except that DTrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   invented its own language for the purpose.  Systemtap, heavily inspired by DTrace, also&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   created its own one-off language, but rather than running the product on an in-kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   interpreter, created an elaborate compiler-based machinery to translate its language into&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   kernel modules written in C.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now that we have the trace data in perf.data, we can use &#039;perf script -g&#039; to generate a skeleton script with handlers for the read/write entry/exit events we recorded:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -g python&lt;br /&gt;
 generated Python script: perf-script.py&lt;br /&gt;
&lt;br /&gt;
The skeleton script simply creates a python function for each event type in the perf.data file.  The body of each function simply prints the event name along with its parameters.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
                print_header(event_name, common_cpu, common_secs, common_nsecs,&lt;br /&gt;
                        common_pid, common_comm)&lt;br /&gt;
  &lt;br /&gt;
 		print &amp;quot;skbaddr=%u, len=%u, name=%s\n&amp;quot; % (skbaddr, len, name),&lt;br /&gt;
&lt;br /&gt;
We can run that script directly to print all of the events contained in the perf.data file:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script -s perf-script.py&lt;br /&gt;
 &lt;br /&gt;
 in trace_begin&lt;br /&gt;
 syscalls__sys_exit_read     0 11624.857082795     1262 perf                  nr=3, ret=0&lt;br /&gt;
 sched__sched_wakeup      0 11624.857193498     1262 perf                  comm=migration/0, pid=6, prio=0, success=1, target_cpu=0&lt;br /&gt;
 irq__softirq_raise       1 11624.858021635     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.858074075     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.858081389     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.858166434     1262 wget                  nr=3, fd=3, buf=3213019456, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.858177924     1262 wget                  nr=3, ret=512&lt;br /&gt;
 skb__kfree_skb           1 11624.858878188     1262 wget                  skbaddr=3945041280, location=3243922184, protocol=0&lt;br /&gt;
 skb__kfree_skb           1 11624.858945608     1262 wget                  skbaddr=3945037824, location=3243922184, protocol=0&lt;br /&gt;
 irq__softirq_raise       1 11624.859020942     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_entry       1 11624.859076935     1262 wget                  vec=TIMER&lt;br /&gt;
 irq__softirq_exit        1 11624.859083469     1262 wget                  vec=TIMER&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859167565     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859192533     1262 wget                  nr=3, ret=471&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859228072     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859233707     1262 wget                  nr=3, ret=0&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859573008     1262 wget                  nr=3, fd=3, buf=3213018496, count=512&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859584818     1262 wget                  nr=3, ret=512&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859864562     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859888770     1262 wget                  nr=3, ret=1024&lt;br /&gt;
 syscalls__sys_enter_read     1 11624.859935140     1262 wget                  nr=3, fd=3, buf=3077701632, count=1024&lt;br /&gt;
 syscalls__sys_exit_read     1 11624.859944032     1262 wget                  nr=3, ret=1024&lt;br /&gt;
&lt;br /&gt;
That in itself isn&#039;t very useful; after all, we can accomplish pretty much the same thing by simply running &#039;perf script&#039; without arguments in the same directory as the perf.data file.&lt;br /&gt;
&lt;br /&gt;
We can however replace the print statements in the generated function bodies with whatever we want, and thereby make it infinitely more useful.&lt;br /&gt;
&lt;br /&gt;
As a simple example, let&#039;s just replace the print statements in the function bodies with a simple function that does nothing but increment a per-event count.  When the program is run against a perf.data file, each time a particular event is encountered, a tally is incremented for that event.  For example:&lt;br /&gt;
&lt;br /&gt;
 def net__netif_rx(event_name, context, common_cpu,&lt;br /&gt;
        common_secs, common_nsecs, common_pid, common_comm,&lt;br /&gt;
        skbaddr, len, name):&lt;br /&gt;
 		inc_counts(event_name)&lt;br /&gt;
&lt;br /&gt;
Each event handler function in the generated code is modified to do this.  For convenience, we define a common function called inc_counts() that each handler calls; inc_counts simply tallies a count for each event using the &#039;counts&#039; hash, which is a specialized has function that does Perl-like autovivification, a capability that&#039;s extremely useful for kinds of multi-level aggregation commonly used in processing traces (see perf&#039;s documentation on the Python language binding for details):&lt;br /&gt;
&lt;br /&gt;
 counts = autodict()&lt;br /&gt;
&lt;br /&gt;
 def inc_counts(event_name):&lt;br /&gt;
        try:&lt;br /&gt;
                counts[event_name] += 1&lt;br /&gt;
        except TypeError:&lt;br /&gt;
                counts[event_name] = 1&lt;br /&gt;
&lt;br /&gt;
Finally, at the end of the trace processing run, we want to print the result of all the per-event tallies.  For that, we use the special &#039;trace_end()&#039; function:&lt;br /&gt;
&lt;br /&gt;
 def trace_end():&lt;br /&gt;
        for event_name, count in counts.iteritems():&lt;br /&gt;
                print &amp;quot;%-40s %10s\n&amp;quot; % (event_name, count)&lt;br /&gt;
&lt;br /&gt;
The end result is a summary of all the events recorded in the trace:&lt;br /&gt;
&lt;br /&gt;
 skb__skb_copy_datagram_iovec                  13148&lt;br /&gt;
 irq__softirq_entry                             4796&lt;br /&gt;
 irq__irq_handler_exit                          3805&lt;br /&gt;
 irq__softirq_exit                              4795&lt;br /&gt;
 syscalls__sys_enter_write                      8990&lt;br /&gt;
 net__net_dev_xmit                               652&lt;br /&gt;
 skb__kfree_skb                                 4047&lt;br /&gt;
 sched__sched_wakeup                            1155&lt;br /&gt;
 irq__irq_handler_entry                         3804&lt;br /&gt;
 irq__softirq_raise                             4799&lt;br /&gt;
 net__net_dev_queue                              652&lt;br /&gt;
 syscalls__sys_enter_read                      17599&lt;br /&gt;
 net__netif_receive_skb                         1743&lt;br /&gt;
 syscalls__sys_exit_read                       17598&lt;br /&gt;
 net__netif_rx                                     2&lt;br /&gt;
 napi__napi_poll                                1877&lt;br /&gt;
 syscalls__sys_exit_write                       8990&lt;br /&gt;
&lt;br /&gt;
Note that this is pretty much exactly the same information we get from &#039;perf stat&#039;, which goes a little way to support the idea mentioned previously that given the right kind of trace data, higher-level profiling-type summaries can be derived from it.&lt;br /&gt;
&lt;br /&gt;
Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding]&lt;br /&gt;
&lt;br /&gt;
===== System-wide tracing and profiling =====&lt;br /&gt;
The examples so far have focused on tracing a particular program or workload - in other words, every profiling run has specified the program to profile in the command-line e.g. &#039;perf record wget ...&#039;.&lt;br /&gt;
&lt;br /&gt;
It&#039;s also possible, and more interesting in many cases, to run a system-wide profile or trace while running the workload in a separate shell.&lt;br /&gt;
&lt;br /&gt;
To do system-wide profiling or tracing, you typically use the -a flag to &#039;perf record&#039;.&lt;br /&gt;
&lt;br /&gt;
To demonstrate this, open up one window and start the profile using the -a flag (press Ctrl-C to stop tracing):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a&lt;br /&gt;
 ^C[ perf record: Woken up 6 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 1.400 MB perf.data (~61172 samples) ]&lt;br /&gt;
&lt;br /&gt;
In another window, run the wget test:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Here we see entries not only for our wget load, but for other processes running on the system as well:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide.gif]]&lt;br /&gt;
&lt;br /&gt;
In the snapshot above, we can see callchains that originate in libc, and a callchain from Xorg that demonstrates that we&#039;re using a proprietary X driver in userspace (notice the presence of &#039;PVR&#039; and some other unresolvable symbols in the expanded Xorg callchain).&lt;br /&gt;
&lt;br /&gt;
Note also that we have both kernel and userspace entries in the above snapshot.  We can also tell perf to focus on userspace but providing a modifier, in this case &#039;u&#039;, to the &#039;cycles&#039; hardware counter when we record a profile:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e cycles:u&lt;br /&gt;
 ^C[ perf record: Woken up 2 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.376 MB perf.data (~16443 samples) ]&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-report-cycles-u.gif]]&lt;br /&gt;
&lt;br /&gt;
Notice in the screenshot above, we see only userspace entries ([.])&lt;br /&gt;
&lt;br /&gt;
Finally, we can press &#039;enter&#039; on a leaf node and select the &#039;Zoom into DSO&#039; menu item to show only entries associated with a specific DSO.  In the screenshot below, we&#039;ve zoomed into the &#039;libc&#039; DSO which shows all the entries associated with the libc-xxx.so DSO.&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-systemwide-libc.gif]]&lt;br /&gt;
&lt;br /&gt;
We can also use the system-wide -a switch to do system-wide tracing.  Here we&#039;ll trace a couple of scheduler events:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch -e sched:sched_wakeup&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.780 MB perf.data (~427299 samples) ]&lt;br /&gt;
&lt;br /&gt;
We can look at the raw output using &#039;perf script&#039; with no arguments:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
            perf  1383 [001]  6171.460045: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.460066: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.460093: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
         swapper     0 [000]  6171.468063: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  6171.468107: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  6171.468143: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.470039: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1383 [001]  6171.470058: sched_switch: prev_comm=perf prev_pid=1383 prev_prio=120 prev_state=R+ ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  6171.470082: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=perf next_pid=1383 next_prio=120&lt;br /&gt;
            perf  1383 [001]  6171.480035: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
&lt;br /&gt;
====== Filtering ======&lt;br /&gt;
&lt;br /&gt;
Notice that there are a lot of events that don&#039;t really have anything to do with what we&#039;re interested in, namely events that schedule &#039;perf&#039; itself in and out or that wake perf up.  We can get rid of those by using the &#039;--filter&#039; 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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -a -e sched:sched_switch --filter &#039;next_comm != perf &amp;amp;&amp;amp; prev_comm != perf&#039; -e sched:sched_wakeup --filter &#039;comm != perf&#039;&lt;br /&gt;
 ^C[ perf record: Woken up 38 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 9.688 MB perf.data (~423279 samples) ]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
         swapper     0 [000]  7932.162180: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.162236: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
            perf  1407 [001]  7932.170048: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.180044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.190038: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.200044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.210044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
            perf  1407 [001]  7932.220044: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230111: sched_wakeup: comm=kworker/1:1 pid=21 prio=120 success=1 target_cpu=001&lt;br /&gt;
         swapper     0 [001]  7932.230146: sched_switch: prev_comm=swapper/1 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/1:1 next_pid=21 next_prio=120&lt;br /&gt;
     kworker/1:1    21 [001]  7932.230205: sched_switch: prev_comm=kworker/1:1 prev_pid=21 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/1 next_pid=0 next_prio=120&lt;br /&gt;
         swapper     0 [000]  7932.326109: sched_wakeup: comm=kworker/0:3 pid=1209 prio=120 success=1 target_cpu=000&lt;br /&gt;
         swapper     0 [000]  7932.326171: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==&amp;gt; next_comm=kworker/0:3 next_pid=1209 next_prio=120&lt;br /&gt;
     kworker/0:3  1209 [000]  7932.326214: sched_switch: prev_comm=kworker/0:3 prev_pid=1209 prev_prio=120 prev_state=S ==&amp;gt; next_comm=swapper/0 next_pid=0 next_prio=120&lt;br /&gt;
&lt;br /&gt;
In this case, we&#039;ve filtered out all events that have &#039;perf&#039; in their &#039;comm&#039; or &#039;comm_prev&#039; or &#039;comm_next&#039; fields.  Notice that there are still events recorded for perf, but notice that those events don&#039;t have values of &#039;perf&#039; for the filtered fields.  To completely filter out anything from perf will require a bit more work, but for the purpose of demonstrating how to use filters, it&#039;s close enough.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These are exactly the same set of event filters defined by the trace event subsystem. See&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   the ftrace/tracecmd/kernelshark section for more discussion about these event filters.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These event filters are implemented by a special-purpose pseudo-interpreter in the kernel&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    and are an integral and indispensable part of the perf design as it relates to tracing.  kernel-&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    based event filters provide a mechanism to precisely throttle the event stream that appears&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    in user space, where it makes sense to provide bindings to real programming languages for&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    postprocessing the event stream.  This architecture allows for the intelligent and flexible&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    partitioning of processing between the kernel and user space.  Contrast this with other tools&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    such as SystemTap, which does all of its processing in the kernel and as such requires a special&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    project-defined language in order to accommodate that design, or LTTng, where everything is sent&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    to userspace and as such requires a super-efficient kernel-to-userspace transport mechanism in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    order to function properly.  While perf certainly can benefit from for instance advances in&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    the design of the transport, it doesn&#039;t fundamentally depend on them.  Basically, if you find&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    that your perf tracing application is causing buffer I/O overruns, it probably means that you&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    aren&#039;t taking enough advantage of the kernel filtering engine.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===== Using dynamic tracepoints =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe do_fork&lt;br /&gt;
 Added new event:&lt;br /&gt;
   probe:do_fork        (on do_fork)&lt;br /&gt;
 &lt;br /&gt;
 You can now use it in all perf tools, such as:&lt;br /&gt;
 &lt;br /&gt;
 	perf record -e probe:do_fork -aR sleep 1&lt;br /&gt;
&lt;br /&gt;
Adding a new tracepoint via &#039;perf probe&#039; results in an event with all the expected files and format in /sys/kernel/debug/tracing/events, just the same as for static tracepoints:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# ls -al&lt;br /&gt;
 drwxr-xr-x    2 root     root             0 Oct 28 11:42 .&lt;br /&gt;
 drwxr-xr-x    3 root     root             0 Oct 28 11:42 ..&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 enable&lt;br /&gt;
 -rw-r--r--    1 root     root             0 Oct 28 11:42 filter&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 format&lt;br /&gt;
 -r--r--r--    1 root     root             0 Oct 28 11:42 id&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing/events/probe/do_fork# cat format&lt;br /&gt;
 name: do_fork&lt;br /&gt;
 ID: 944&lt;br /&gt;
 format:&lt;br /&gt;
 	field:unsigned short common_type;	offset:0;	size:2;	signed:0; &lt;br /&gt;
 	field:unsigned char common_flags;	offset:2;	size:1;	signed:0;&lt;br /&gt;
 	field:unsigned char common_preempt_count;	offset:3;	size:1;	signed:0;&lt;br /&gt;
 	field:int common_pid;	offset:4;	size:4;	signed:1;&lt;br /&gt;
 	field:int common_padding;	offset:8;	size:4;	signed:1;&lt;br /&gt;
 &lt;br /&gt;
 	field:unsigned long __probe_ip;	offset:12;	size:4;	signed:0;&lt;br /&gt;
 &lt;br /&gt;
 print fmt: &amp;quot;(%lx)&amp;quot;, REC-&amp;gt;__probe_ip&lt;br /&gt;
&lt;br /&gt;
We can list all dynamic tracepoints currently in existence:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf probe -l&lt;br /&gt;
  probe:do_fork        (on do_fork)&lt;br /&gt;
  probe:schedule       (on schedule)&lt;br /&gt;
&lt;br /&gt;
Let&#039;s record system-wide (&#039;sleep 30&#039; is a trick for recording system-wide but basically do nothing and then wake up after 30 seconds):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf record -g -a -e probe:do_fork sleep 30&lt;br /&gt;
 [ perf record: Woken up 1 times to write data ]&lt;br /&gt;
 [ perf record: Captured and wrote 0.087 MB perf.data (~3812 samples) ]&lt;br /&gt;
&lt;br /&gt;
Using &#039;perf script&#039; we can see each do_fork event that fired:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# perf script&lt;br /&gt;
 &lt;br /&gt;
 # ========&lt;br /&gt;
 # captured on: Sun Oct 28 11:55:18 2012&lt;br /&gt;
 # hostname : crownbay&lt;br /&gt;
 # os release : 3.4.11-yocto-standard&lt;br /&gt;
 # perf version : 3.4.11&lt;br /&gt;
 # arch : i686&lt;br /&gt;
 # nrcpus online : 2&lt;br /&gt;
 # nrcpus avail : 2&lt;br /&gt;
 # cpudesc : Intel(R) Atom(TM) CPU E660 @ 1.30GHz&lt;br /&gt;
 # cpuid : GenuineIntel,6,38,1&lt;br /&gt;
 # total memory : 1017184 kB&lt;br /&gt;
 # cmdline : /usr/bin/perf record -g -a -e probe:do_fork sleep 30 &lt;br /&gt;
 # event : name = probe:do_fork, type = 2, config = 0x3b0, config1 = 0x0, config2 = 0x0, excl_usr = 0, excl_kern&lt;br /&gt;
  = 0, id = { 5, 6 }&lt;br /&gt;
 # HEADER_CPU_TOPOLOGY info available, use -I to display&lt;br /&gt;
 # ========&lt;br /&gt;
 #&lt;br /&gt;
  matchbox-deskto  1197 [001] 34211.378318: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1295 [001] 34211.380388: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.632350: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34211.639917: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34217.541603: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1299 [001] 34217.543584: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34217.697451: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.085734: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [000] 34219.121351: do_fork: (c1028460)&lt;br /&gt;
           gthumb  1300 [001] 34219.264551: do_fork: (c1028460)&lt;br /&gt;
          pcmanfm  1296 [000] 34219.590380: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34224.955965: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1306 [001] 34224.957972: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.038214: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [001] 34225.044218: do_fork: (c1028460)&lt;br /&gt;
  matchbox-termin  1307 [000] 34225.046442: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1197 [001] 34237.112138: do_fork: (c1028460)&lt;br /&gt;
  matchbox-deskto  1311 [001] 34237.114106: do_fork: (c1028460)&lt;br /&gt;
             gaku  1312 [000] 34237.202388: do_fork: (c1028460)&lt;br /&gt;
&lt;br /&gt;
And using &#039;perf report&#039; on the same file, we can see the callgraphs from starting a few programs during those 30 seconds:&lt;br /&gt;
&lt;br /&gt;
[[File:Perf-probe-do_fork-profile.gif]]&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The trace events subsystem accomodate static and dynamic tracepoints in exactly the&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   same way - there&#039;s no difference as far as the infrastructure is concerned.  See the ftrace&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   section for more details on the trace event subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Dynamic tracepoints are implemented under the covers by kprobes and uprobes.  kprobes and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   uprobes are also used by and in fact are the main focus of SystemTap.&#039;&#039;&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-stat &#039;perf stat&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-record &#039;perf record&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-report &#039;perf report&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-probe &#039;perf probe&#039; manpage].&lt;br /&gt;
*The [http://linux.die.net/man/1/perf-script &#039;perf script&#039; manpage]. &lt;br /&gt;
*Documentation on using the [http://linux.die.net/man/1/perf-script-python &#039;perf script&#039; python binding].&lt;br /&gt;
*The top-level [http://linux.die.net/man/1/perf perf(1) manpage].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Normally, you should be able to invoke the man pages via perf itself e.g. &#039;perf help&#039; or &#039;perf help record&#039;.&lt;br /&gt;
&lt;br /&gt;
However, by default Yocto doesn&#039;t install man pages, but perf invokes the man pages for most help functionality.  This is a bug and is being addressed by a Yocto bug: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3388 Bug 3388 - perf: enable man pages for basic &#039;help&#039; functionality]&lt;br /&gt;
&lt;br /&gt;
=== ftrace ===&lt;br /&gt;
&#039;ftrace&#039; literally refers to the &#039;ftrace function tracer&#039; but in reality this encompasses a number of related tracers along with the infrastructure that they all make use of.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
ftrace, trace-cmd, and kernelshark run on the target system, and are ready to go out-of-the-box - no additional setup is necessary.  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running ftrace on the target.  kernelshark is a GUI application and if you use the &#039;-X&#039; option to ssh you can have the kernelshark GUI run on the target but display remotely on the host if you want.&lt;br /&gt;
&lt;br /&gt;
==== Basic ftrace usage ====&lt;br /&gt;
&lt;br /&gt;
&#039;ftrace&#039; 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).  Here&#039;s a listing of all the files found in /sys/kernel/debug/tracing on a Yocto system.:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# ls&lt;br /&gt;
 README                      kprobe_events               trace&lt;br /&gt;
 available_events            kprobe_profile              trace_clock&lt;br /&gt;
 available_filter_functions  options                     trace_marker&lt;br /&gt;
 available_tracers           per_cpu                     trace_options&lt;br /&gt;
 buffer_size_kb              printk_formats              trace_pipe&lt;br /&gt;
 buffer_total_size_kb        saved_cmdlines              tracing_cpumask&lt;br /&gt;
 current_tracer              set_event                   tracing_enabled&lt;br /&gt;
 dyn_ftrace_total_info       set_ftrace_filter           tracing_on&lt;br /&gt;
 enabled_functions           set_ftrace_notrace          tracing_thresh&lt;br /&gt;
 events                      set_ftrace_pid&lt;br /&gt;
 free_buffer                 set_graph_function&lt;br /&gt;
&lt;br /&gt;
The files listed above are used for various purposes - some relate directly to the tracers themselves, others are used to set tracing options, and yet others actually contain the tracing output when a tracer is in effect.  Some of the functions can be guessed from their names, others need explanation; in any case, we&#039;ll cover some of the files we see here below but for an explanation of the others, please see [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Documentation_2 the ftrace documentation].&lt;br /&gt;
&lt;br /&gt;
We&#039;ll start by looking at some of the available built-in tracers.&lt;br /&gt;
&lt;br /&gt;
cat&#039;ing the &#039;available_tracers&#039; file lists the set of available tracers:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
The &#039;current_tracer&#039; file contains the tracer currently in effect:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 nop&lt;br /&gt;
&lt;br /&gt;
The above listing of current_tracer shows that the &#039;nop&#039; tracer is in effect, which is just another way of saying that there&#039;s actually no tracer currently in effect.&lt;br /&gt;
&lt;br /&gt;
echo&#039;ing one of the available_tracers into current_tracer makes the specified tracer the current tracer:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# echo function &amp;gt; current_tracer&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cat current_tracer &lt;br /&gt;
 function&lt;br /&gt;
&lt;br /&gt;
The above sets the current tracer to be the &#039;function tracer&#039;.  This tracer traces every function call in the kernel and makes it available as the contents of the &#039;trace&#039; file.  Reading the &#039;trace&#039; file lists the currently buffered function calls that have been traced by the function tracer:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;The ftrace function tracer is also available from within perf, as the ftrace:function tracepoint.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== The &#039;trace events&#039; subsystem ====&lt;br /&gt;
&lt;br /&gt;
One especially important directory contained within the /sys/kernel/debug/tracing directory is the &#039;events&#039; subdirectory, which contains representations of every tracepoint in the system:&lt;br /&gt;
&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing# cd events&lt;br /&gt;
 root@sugarbay:/sys/kernel/debug/tracing/events# ls&lt;br /&gt;
 block         ftrace        jbd           oom           rpm           sunrpc        vsyscall&lt;br /&gt;
 btrfs         hda           jbd2          power         sched         syscalls      workqueue&lt;br /&gt;
 drm           header_event  kmem          printk        scsi          task          writeback&lt;br /&gt;
 enable        header_page   module        random        signal        timer&lt;br /&gt;
 ext3          i915          napi          raw_syscalls  skb           udp&lt;br /&gt;
 ext4          irq           net           rcu           sock          vmscan&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;These tracepoints and their representation are used not only by ftrace,  but by many&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    of the other tools covered in this document and they form a central point of integration&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the various tracers available in Linux.  They form a central part of the instrumentation&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   for the following tools: perf, lttng, ftrace, blktrace and SystemTap&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;Eventually all the special-purpose tracers currently available in /sys/kernel/debug/tracing&#039;&#039;&lt;br /&gt;
 &#039;&#039;                    will be removed and replaced with equivalent tracers based on the &#039;trace events&#039; subsystem.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== trace-cmd/kernelshark ====&lt;br /&gt;
trace-cmd is essentially an extensive command-line &#039;wrapper&#039; interface that hides the details of all the individual files in /sys/kernel/debug/tracing, allowing users to specify specific particular events within the /sys/kernel/debug/tracing/events/ subdirectory and to collect traces and avoiding having to deal with those details directly.&lt;br /&gt;
&lt;br /&gt;
As yet another layer on top of that, kernelshark provides a GUI that allows users to start and stop traces and specify sets of events using an intuitive interface, and view the output as both trace events and as a per-cpu graphical display.  It directly uses &#039;trace-cmd&#039; as the plumbing that accomplishes all that underneath the covers (and actually displays the trace-cmd command it uses, as we&#039;ll see).&lt;br /&gt;
&lt;br /&gt;
[[File:Kernelshark-choose-events.gif]]&lt;br /&gt;
[[File:Kernelshark-output-display.gif]]&lt;br /&gt;
[[File:Kernelshark-i915-display.gif]]&lt;br /&gt;
[[File:Kernelshark-all.gif]]&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The documentation for ftrace can be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/ftrace.txt&lt;br /&gt;
&lt;br /&gt;
The documentation for the trace event subsystem can also be found in the kernel Documentation directory:&lt;br /&gt;
 Documentation/trace/events.txt&lt;br /&gt;
&lt;br /&gt;
An amusing yet useful README (a tracing mini-HOWTO) can be found in /sys/kernel/debug/tracing/README.&lt;br /&gt;
&lt;br /&gt;
=== oprofile ===&lt;br /&gt;
==== Setup ====&lt;br /&gt;
&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
oprofile itself is a command-line application that runs on the target system.  For the the section that deals with oprofile from the command-line, we assume you&#039;ve ssh&#039;ed to the host and will be running oprofile on the target.&lt;br /&gt;
&lt;br /&gt;
oprofileui (oprofile-viewer) is a GUI-based program that runs on the host and interacts remotely with the target.  See the oprofileui section for the exact steps needed to install oprofileui on the host.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
Oprofile as configured in Yocto is a system-wide profiler (i.e. the version in Yocto doesn&#039;t yet make use of the perf_events interface which would allow it to profile specific processes and workloads).  It&#039;s relies on hardware counter support in the hardware (but can fall back to a timer-based mode), which means that it doesn&#039;t take advantage of tracepoints or other event sources for example.&lt;br /&gt;
&lt;br /&gt;
It consists of a kernel module that collects samples and a userspace daemon that writes the sample data to disk.&lt;br /&gt;
&lt;br /&gt;
The &#039;opcontrol&#039; shell script is used for transparently managing these components and starting and stopping profiles, and the &#039;opreport&#039; command is used to display the results.&lt;br /&gt;
&lt;br /&gt;
The oprofile daemon should already be running, but before you start profiling, you may need to change some settings and some of these settings may require the daemon not be running.  One of these settings is the path the the vmlinux file, which you&#039;ll want to set using the --vmlinux option if you want the kernel profiled:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 The profiling daemon is currently active, so changes to the configuration&lt;br /&gt;
 will be used the next time you restart oprofile after a --shutdown or --deinit.&lt;br /&gt;
&lt;br /&gt;
You can check if vmlinux file: is set using opcontrol --status:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1334&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: none&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
If it&#039;s not, you need to shutdown the daemon, add the setting and restart the daemon:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
 &lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
 Using default event: CPU_CLK_UNHALTED:100000:0:1:1&lt;br /&gt;
 Using 2.6+ OProfile kernel interface.&lt;br /&gt;
 Reading module info.&lt;br /&gt;
 Using log file /var/lib/oprofile/samples/oprofiled.log&lt;br /&gt;
 Daemon started.&lt;br /&gt;
&lt;br /&gt;
If we get the status again we now see our updated settings:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
 Daemon paused: pid 1649&lt;br /&gt;
 Separate options: library&lt;br /&gt;
 vmlinux file: /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 Image filter: none&lt;br /&gt;
 Call-graph depth: 6&lt;br /&gt;
&lt;br /&gt;
We&#039;re now in a position to run a profile.  For that we used &#039;opcontrol --start&#039;:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Profiler running.&lt;br /&gt;
&lt;br /&gt;
In another window, run our wget workload:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
To stop the profile we use &#039;opcontrol --shudown&#039;, which not only stops the profile but shuts down the daemon as well:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --start&lt;br /&gt;
 Stopping profiling.&lt;br /&gt;
 Killing daemon.&lt;br /&gt;
&lt;br /&gt;
Oprofile writes sample data to /var/lib/oprofile/samples, which you can look at if you&#039;re interested in seeing how the samples are structured.  This is also interesting because it&#039;s related to how you dive down to get further details about specific executables in OProfile.&lt;br /&gt;
&lt;br /&gt;
To see the default display output for a profile, simply type &#039;opreport&#039;, which will show the results using the data in /var/lib/oprofile/samples: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport&lt;br /&gt;
 &lt;br /&gt;
 WARNING! The OProfile kernel driver reports sample buffer overflows.&lt;br /&gt;
 Such overflows can result in incorrect sample attribution, invalid sample&lt;br /&gt;
 files and other symptoms.  See the oprofiled.log for details.&lt;br /&gt;
 You should adjust your sampling frequency to eliminate (or at least minimize)&lt;br /&gt;
 these overflows.&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
 ------------------&lt;br /&gt;
   464365 79.8156 vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
  	------------------&lt;br /&gt;
  	    64416 98.9372 oprofiled&lt;br /&gt;
  	      692  1.0628 libc-2.16.so&lt;br /&gt;
    36959  6.3526 no-vmlinux&lt;br /&gt;
     4378  0.7525 busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 busybox&lt;br /&gt;
 	      193  4.4084 ld-2.16.so&lt;br /&gt;
 	        2  0.0457 libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 bash&lt;br /&gt;
 	     1665 38.3287 libc-2.16.so&lt;br /&gt;
 	       18  0.4144 ld-2.16.so&lt;br /&gt;
 	        3  0.0691 libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 libdl-2.16.so&lt;br /&gt;
     3118  0.5359 nf_conntrack&lt;br /&gt;
      686  0.1179 matchbox-terminal&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      214 31.1953 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	      114 16.6181 libc-2.16.so&lt;br /&gt;
 	       79 11.5160 libcairo.so.2.11200.2&lt;br /&gt;
 	       78 11.3703 libgdk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       51  7.4344 libpthread-2.16.so&lt;br /&gt;
 	       45  6.5598 libgobject-2.0.so.0.3200.4&lt;br /&gt;
 	       29  4.2274 libvte.so.9.2800.2&lt;br /&gt;
 	       25  3.6443 libX11.so.6.3.0&lt;br /&gt;
 	       19  2.7697 libxcb.so.1.1.0&lt;br /&gt;
 	       17  2.4781 libgtk-x11-2.0.so.0.2400.8&lt;br /&gt;
 	       12  1.7493 librt-2.16.so&lt;br /&gt;
 	        3  0.4373 libXrender.so.1.3.0&lt;br /&gt;
      671  0.1153 emgd&lt;br /&gt;
      411  0.0706 nf_conntrack_ipv4&lt;br /&gt;
      391  0.0672 iptable_nat&lt;br /&gt;
      378  0.0650 nf_nat&lt;br /&gt;
      263  0.0452 Xorg&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	      106 40.3042 Xorg&lt;br /&gt;
 	       53 20.1521 libc-2.16.so&lt;br /&gt;
 	       31 11.7871 libpixman-1.so.0.27.2&lt;br /&gt;
 	       26  9.8859 emgd_drv.so&lt;br /&gt;
 	       16  6.0837 libemgdsrv_um.so.1.5.15.3226&lt;br /&gt;
 	       11  4.1825 libEMGD2d.so.1.5.15.3226&lt;br /&gt;
 	        9  3.4221 libfb.so&lt;br /&gt;
 	        7  2.6616 libpthread-2.16.so&lt;br /&gt;
 	        1  0.3802 libudev.so.0.9.3&lt;br /&gt;
 	        1  0.3802 libdrm.so.2.4.0&lt;br /&gt;
 	        1  0.3802 libextmod.so&lt;br /&gt;
 	        1  0.3802 mouse_drv.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
       9  0.0015 connmand&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        4 44.4444 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        2 22.2222 libpthread-2.16.so&lt;br /&gt;
 	        1 11.1111 connmand&lt;br /&gt;
 	        1 11.1111 libc-2.16.so&lt;br /&gt;
 	        1 11.1111 librt-2.16.so&lt;br /&gt;
        6  0.0010 oprofile-server&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        3 50.0000 libc-2.16.so&lt;br /&gt;
 	        1 16.6667 oprofile-server&lt;br /&gt;
 	        1 16.6667 libpthread-2.16.so&lt;br /&gt;
 	        1 16.6667 libglib-2.0.so.0.3200.4&lt;br /&gt;
        5 8.6e-04 gconfd-2&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	        2 40.0000 libdbus-1.so.3.7.2&lt;br /&gt;
 	        2 40.0000 libglib-2.0.so.0.3200.4&lt;br /&gt;
 	        1 20.0000 libc-2.16.so&lt;br /&gt;
&lt;br /&gt;
The output above shows the breakdown or samples by both number of samples and percentage for each executable.  Within an executable, the sample counts are broken down further into executable and shared libraries (DSOs) used by the executable.&lt;br /&gt;
&lt;br /&gt;
To get even more detailed breakdowns by function, we need to have the full paths to the DSOs, which we can get by using -f with opreport:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -f&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 CPU_CLK_UNHALT...|&lt;br /&gt;
  samples|      %|&lt;br /&gt;
------------------&lt;br /&gt;
   464365 79.8156 /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
    65108 11.1908 /usr/bin/oprofiled&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	    64416 98.9372 /usr/bin/oprofiled&lt;br /&gt;
 	      692  1.0628 /lib/libc-2.16.so&lt;br /&gt;
    36959  6.3526 /no-vmlinux&lt;br /&gt;
     4378  0.7525 /bin/busybox&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2844 64.9612 /lib/libc-2.16.so&lt;br /&gt;
 	     1337 30.5391 /bin/busybox&lt;br /&gt;
 	      193  4.4084 /lib/ld-2.16.so&lt;br /&gt;
 	        2  0.0457 /lib/libnss_compat-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnsl-2.16.so&lt;br /&gt;
 	        1  0.0228 /lib/libnss_files-2.16.so&lt;br /&gt;
     4344  0.7467 /bin/bash&lt;br /&gt;
 	CPU_CLK_UNHALT...|&lt;br /&gt;
 	  samples|      %|&lt;br /&gt;
 	------------------&lt;br /&gt;
 	     2657 61.1648 /bin/bash&lt;br /&gt;
 	     1665 38.3287 /lib/libc-2.16.so&lt;br /&gt;
 	       18  0.4144 /lib/ld-2.16.so&lt;br /&gt;
 	        3  0.0691 /lib/libtinfo.so.5.9&lt;br /&gt;
 	        1  0.0230 /lib/libdl-2.16.so&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Using the paths shown in the above output and the -l option to opreport, we can see all the functions that have hits in the profile and their sample counts and percentages.  Here&#039;s a portion of what we get for the kernel:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport -l /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        symbol name&lt;br /&gt;
 233981   50.3873  intel_idle&lt;br /&gt;
 15437     3.3243  rb_get_reader_page&lt;br /&gt;
 14503     3.1232  ring_buffer_consume&lt;br /&gt;
 14092     3.0347  mutex_spin_on_owner&lt;br /&gt;
 13024     2.8047  read_hpet&lt;br /&gt;
 8039      1.7312  sub_preempt_count&lt;br /&gt;
 7096      1.5281  ioread32&lt;br /&gt;
 6997      1.5068  add_preempt_count&lt;br /&gt;
 3985      0.8582  rb_advance_reader&lt;br /&gt;
 3488      0.7511  add_event_entry&lt;br /&gt;
 3303      0.7113  get_parent_ip&lt;br /&gt;
 3104      0.6684  rb_buffer_peek&lt;br /&gt;
 2960      0.6374  op_cpu_buffer_read_entry&lt;br /&gt;
 2614      0.5629  sync_buffer&lt;br /&gt;
 2545      0.5481  debug_smp_processor_id&lt;br /&gt;
 2456      0.5289  ohci_irq&lt;br /&gt;
 2397      0.5162  memset&lt;br /&gt;
 2349      0.5059  __copy_to_user_ll&lt;br /&gt;
 2185      0.4705  ring_buffer_event_length&lt;br /&gt;
 1918      0.4130  in_lock_functions&lt;br /&gt;
 1850      0.3984  __schedule&lt;br /&gt;
 1767      0.3805  __copy_from_user_ll_nozero&lt;br /&gt;
 1575      0.3392  rb_event_data_length&lt;br /&gt;
 1256      0.2705  memcpy&lt;br /&gt;
 1233      0.2655  system_call&lt;br /&gt;
 1213      0.2612  menu_select&lt;br /&gt;
&lt;br /&gt;
Notice that above we see an entry for the __copy_to_user_ll() function that we&#039;ve looked at with other profilers as well.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s what we get when we do the same thing for the busybox executable:&lt;br /&gt;
&lt;br /&gt;
 CPU: Intel Architectural Perfmon, speed 1.3e+06 MHz (estimated)&lt;br /&gt;
 Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000&lt;br /&gt;
 samples  %        image name               symbol name&lt;br /&gt;
 349       8.4198  busybox                  retrieve_file_data&lt;br /&gt;
 308       7.4306  libc-2.16.so             _IO_file_xsgetn&lt;br /&gt;
 283       6.8275  libc-2.16.so             __read_nocancel&lt;br /&gt;
 235       5.6695  libc-2.16.so             syscall&lt;br /&gt;
 233       5.6212  libc-2.16.so             clearerr&lt;br /&gt;
 215       5.1870  libc-2.16.so             fread&lt;br /&gt;
 181       4.3667  libc-2.16.so             __write_nocancel&lt;br /&gt;
 158       3.8118  libc-2.16.so             __underflow&lt;br /&gt;
 151       3.6429  libc-2.16.so             _dl_addr&lt;br /&gt;
 150       3.6188  busybox                  progress_meter&lt;br /&gt;
 150       3.6188  libc-2.16.so             __poll_nocancel&lt;br /&gt;
 148       3.5706  libc-2.16.so             _IO_file_underflow@@GLIBC_2.1&lt;br /&gt;
 137       3.3052  busybox                  safe_poll&lt;br /&gt;
 125       3.0157  busybox                  bb_progress_update&lt;br /&gt;
 122       2.9433  libc-2.16.so             __x86.get_pc_thunk.bx&lt;br /&gt;
 95        2.2919  busybox                  full_write&lt;br /&gt;
 81        1.9542  busybox                  safe_write&lt;br /&gt;
 77        1.8577  busybox                  xwrite&lt;br /&gt;
 72        1.7370  libc-2.16.so             _IO_file_read&lt;br /&gt;
 71        1.7129  libc-2.16.so             _IO_sgetn&lt;br /&gt;
 67        1.6164  libc-2.16.so             poll&lt;br /&gt;
 52        1.2545  libc-2.16.so             _IO_switch_to_get_mode&lt;br /&gt;
 45        1.0856  libc-2.16.so             read&lt;br /&gt;
 34        0.8203  libc-2.16.so             write&lt;br /&gt;
 32        0.7720  busybox                  monotonic_sec&lt;br /&gt;
 25        0.6031  libc-2.16.so             vfprintf&lt;br /&gt;
 22        0.5308  busybox                  get_mono&lt;br /&gt;
 14        0.3378  ld-2.16.so               strcmp&lt;br /&gt;
 14        0.3378  libc-2.16.so             __x86.get_pc_thunk.cx&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
Since we recorded the profile with a callchain depth of 6, we should be able to see our __copy_to_user_ll() callchains in the output, and indeed we can if we search around a bit in the &#039;opreport --callgraph&#039; output:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opreport --callgraph /boot/vmlinux-3.4.11-yocto-standard&lt;br /&gt;
 &lt;br /&gt;
   392       6.9639  vmlinux-3.4.11-yocto-standard sock_aio_read&lt;br /&gt;
   736      13.0751  vmlinux-3.4.11-yocto-standard __generic_file_aio_write&lt;br /&gt;
   3255     57.8255  vmlinux-3.4.11-yocto-standard inet_recvmsg&lt;br /&gt;
 785       0.1690  vmlinux-3.4.11-yocto-standard tcp_recvmsg&lt;br /&gt;
   1790     31.7940  vmlinux-3.4.11-yocto-standard local_bh_enable&lt;br /&gt;
   1238     21.9893  vmlinux-3.4.11-yocto-standard __kfree_skb&lt;br /&gt;
   992      17.6199  vmlinux-3.4.11-yocto-standard lock_sock_nested&lt;br /&gt;
   785      13.9432  vmlinux-3.4.11-yocto-standard tcp_recvmsg [self]&lt;br /&gt;
   525       9.3250  vmlinux-3.4.11-yocto-standard release_sock&lt;br /&gt;
   112       1.9893  vmlinux-3.4.11-yocto-standard tcp_cleanup_rbuf&lt;br /&gt;
   72        1.2789  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
 &lt;br /&gt;
 170       0.0366  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   1491     73.3038  vmlinux-3.4.11-yocto-standard memcpy_toiovec&lt;br /&gt;
   327      16.0767  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec&lt;br /&gt;
   170       8.3579  vmlinux-3.4.11-yocto-standard skb_copy_datagram_iovec [self]&lt;br /&gt;
   20        0.9833  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 &lt;br /&gt;
   2588     98.2909  vmlinux-3.4.11-yocto-standard copy_to_user&lt;br /&gt;
 2349      0.5059  vmlinux-3.4.11-yocto-standard __copy_to_user_ll&lt;br /&gt;
   2349     89.2138  vmlinux-3.4.11-yocto-standard __copy_to_user_ll [self]&lt;br /&gt;
   166       6.3046  vmlinux-3.4.11-yocto-standard do_page_fault&lt;br /&gt;
&lt;br /&gt;
Remember that by default OProfile sessions are cumulative i.e. if you start and stop a profiling session, then start a new one, the new one will not erase the previous run(s) but will build on it.  If you want to restart a profile from scratch, you need to reset:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --reset&lt;br /&gt;
&lt;br /&gt;
==== OProfileUI - A GUI for OProfile ====&lt;br /&gt;
&lt;br /&gt;
Yocto also supports a graphical UI for controlling and viewing OProfile traces, called OProfileUI.  To use it, you first need to clone the oprofileui git repo, then configure, build, and install it:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada tmp]$ git clone git://git.yoctoproject.org/oprofileui&lt;br /&gt;
 [trz@empanada tmp]$ cd oprofileui&lt;br /&gt;
 [trz@empanada oprofileui]$ ./autogen.sh&lt;br /&gt;
 [trz@empanada oprofileui]$ sudo make install&lt;br /&gt;
&lt;br /&gt;
OprofileUI replaces the &#039;opreport&#039; functionality with a GUI, and normally doesn&#039;t require the user to use &#039;opcontrol&#039; either.  If you want to profile the kernel, however, you need to either use the UI to specify a vmlinux or use &#039;opcontrol&#039; to specify it on the target:&lt;br /&gt;
&lt;br /&gt;
First, on the target, check if vmlinux file: is set:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --status&lt;br /&gt;
&lt;br /&gt;
If not:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# opcontrol --shutdown&lt;br /&gt;
 root@crownbay:~# opcontrol --vmlinux=/boot/vmlinux-`uname -r`&lt;br /&gt;
 root@crownbay:~# opcontrol --start-daemon&lt;br /&gt;
&lt;br /&gt;
Now, start the oprofile UI on the host system:&lt;br /&gt;
&lt;br /&gt;
 [trz@empanada oprofileui]$ oprofile-viewer&lt;br /&gt;
&lt;br /&gt;
To run a profile on the remote system, first connect to the remote system by pressing the &#039;Connect&#039; button and supplying the IP address and port of the remote system (the default port is 4224).&lt;br /&gt;
&lt;br /&gt;
The oprofile server should automatically be started already.  If not, the connection will fail and you either typed in the wrong IP address and port (see below), or you need to start the server yourself:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server&lt;br /&gt;
&lt;br /&gt;
Or, to specify a specific port:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# oprofile-server --port 8888&lt;br /&gt;
&lt;br /&gt;
Once connected, press the &#039;Start&#039; button and then run the wget workload on the remote system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
Once the workload completes, press the &#039;Stop&#039; button.  At that point the OProfile viewer will download the profile files it&#039;s collected (this may take some time, especially if the kernel was profiled).  While it downloads the files, you should see something like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-downloading.gif]]&lt;br /&gt;
&lt;br /&gt;
Once the profile files have been retrieved, you should see a list of the processes that were profiled:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-processes.gif]]&lt;br /&gt;
&lt;br /&gt;
If you select one of them, you should see all the symbols that were hit during the profile.  Selecting one of them will show a list of callers and callees of the chosen function in two panes below the top pane.  For example, here&#039;s what we see when we select __copy_to_user_ll():&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
As another example, we can look at the busybox process and see that the progress meter made a system call:&lt;br /&gt;
&lt;br /&gt;
[[File:Oprofileui-busybox.gif]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;oprofile does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Yocto already has some information on setting up and using OProfile and oprofileui.  As this document doesn&#039;t cover everything in detail, it may be worth taking a look: &lt;br /&gt;
[http://www.yoctoproject.org/docs/current/dev-manual/dev-manual.html#platdev-oprofile Yocto Project Development Manual - Profiling with OProfile]&lt;br /&gt;
&lt;br /&gt;
The OProfile manual can be found here:&lt;br /&gt;
[http://oprofile.sourceforge.net/doc/index.html OProfile manual]&lt;br /&gt;
&lt;br /&gt;
The OProfile website contains links to the above manual and bunch of other items including an extensive set of examples:&lt;br /&gt;
[http://oprofile.sourceforge.net/about/ About OProfile]&lt;br /&gt;
&lt;br /&gt;
=== Sysprof ===&lt;br /&gt;
&lt;br /&gt;
Sysprof is a very easy to use system-wide profiler that consists of a single window with three panes and a few buttons which allow you to start, stop, and view the profile from one place.&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
Sysprof is a GUI-based application that runs on the target system.  For the rest of this document we assume you&#039;ve ssh&#039;ed to the host and will be running Sysprof on the target (you can use the &#039;-X&#039; option to ssh and have the Sysprof GUI run on the target but display remotely on the host if you want).&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To start profiling the system, you simply press the &#039;Start&#039; button.  To stop profiling and to start viewing the profile data in one easy step, press the &#039;Profile&#039; button.&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve pressed the profile button, the three panes will fill up with profiling data:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-to-user.gif]]&lt;br /&gt;
&lt;br /&gt;
The left pane shows a list of functions and processes.  Selecting one of those expands that function in the right pane, showing all its callees.  Note that this caller-oriented display is essentially the inverse of perf&#039;s default callee-oriented callchain display.&lt;br /&gt;
&lt;br /&gt;
In the screenshot above, we&#039;re focusing on __copy_to_user_ll() and looking up the callchain we can see that one of the callers of __copy_to_user_ll is sys_read() and the complete callpath between them.  Notice that this is essentially a portion of the same information we saw in the perf display shown in the perf section of this page.&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-copy-from-user.gif]]&lt;br /&gt;
&lt;br /&gt;
Similarly, the above is a snapshot of the Sysprof display of a copy-from-user callchain.&lt;br /&gt;
&lt;br /&gt;
Finally, looking at the third Sysprof pane in the lower left, we can see a list of all the callers of a particular function selected in the top left pane.  In this case, the lower pane is showing all the callers of __mark_inode_dirty:&lt;br /&gt;
&lt;br /&gt;
[[File:Sysprof-callers.gif]]&lt;br /&gt;
&lt;br /&gt;
Double-clicking on one of those functions will in turn change the focus to the selected function, and so on.&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;If you like sysprof&#039;s &#039;caller-oriented&#039; display, you may be able to approximate&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   it in other tools as well.  For example, &#039;perf report&#039; has the -g (--call-graph) option&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   that you can experiment with; one of the options is &#039;caller&#039; for an inverted caller-based&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   callgraph display.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Tying It Together&#039;&#039;&#039;: &#039;&#039;sysprof does have build options to enable use of the perf_event subsystem and&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   benefit from the perf_event infrastructure by adding support for something other than&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   system-wide profiling i.e. per-process or workload profiling, but the version in danny&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   doesn&#039;t yet take advantage of those capabilities (sysprof officially added the ability.&#039;&#039;&lt;br /&gt;
 &#039;&#039;                   to make use of perf_events just as we were going to press).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
There doesn&#039;t seem to be any documentation for Sysprof, but maybe that&#039;s because it&#039;s pretty self-explanatory.  The Sysprof website, however, is here:&lt;br /&gt;
&lt;br /&gt;
[http://sysprof.com/ Sysprof, System-wide Performance Profiler for Linux]&lt;br /&gt;
&lt;br /&gt;
=== LTTng (Linux Trace Toolkit, next generation) ===&lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
NOTE: The lttng support in Yocto 1.3 (danny) needs the following poky commits applied in order to work:&lt;br /&gt;
&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/switch-to-lttng2&amp;amp;id=ea602300d9211669df0acc5c346e4486d6bf6f67&lt;br /&gt;
*http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=tzanussi/lttng-fixes.0&amp;amp;id=1d0dc88e1635cfc24612a3e97d0391facdc2c65f&lt;br /&gt;
&lt;br /&gt;
If you also want to view the LTTng traces graphically, you also need to download and install/run the &#039;SR1&#039; or later Juno release of eclipse e.g.:&lt;br /&gt;
&lt;br /&gt;
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/juno/SR1/eclipse-cpp-juno-SR1-linux-gtk-x86_64.tar.gz&lt;br /&gt;
&lt;br /&gt;
==== Collecting and Viewing Traces ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve applied the above commits and built and booted your image (you need to build the core-image-sato-sdk image or the other methods described in the General Setup section), you&#039;re ready to start tracing.&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace on the target (inside a shell) =====&lt;br /&gt;
&lt;br /&gt;
First, from the target, ssh to the target:&lt;br /&gt;
&lt;br /&gt;
 $ ssh -l root 192.168.1.47&lt;br /&gt;
 The authenticity of host &#039;192.168.1.47 (192.168.1.47)&#039; can&#039;t be established.&lt;br /&gt;
 RSA key fingerprint is 23:bd:c8:b1:a8:71:52:00:ee:00:4f:64:9e:10:b9:7e.&lt;br /&gt;
 Are you sure you want to continue connecting (yes/no)? yes&lt;br /&gt;
 Warning: Permanently added &#039;192.168.1.47&#039; (RSA) to the list of known hosts.&lt;br /&gt;
 root@192.168.1.47&#039;s password:&lt;br /&gt;
&lt;br /&gt;
Once on the target, use these steps to create a trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng create&lt;br /&gt;
 Spawning a session daemon&lt;br /&gt;
 Session auto-20121015-232120 created.&lt;br /&gt;
 Traces will be written in /home/root/lttng-traces/auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
Enable the events you want to trace (in this case all kernel events):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng enable-event --kernel --all&lt;br /&gt;
 All kernel events are enabled in channel channel0&lt;br /&gt;
&lt;br /&gt;
Start the trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng start&lt;br /&gt;
 Tracing started for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
And then stop the trace after awhile or after running a particular workload that you want to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng stop&lt;br /&gt;
 Tracing stopped for session auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
You can now view the trace in text form on the target:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng view&lt;br /&gt;
 [23:21:56.989270399] (+?.?????????) sys_geteuid: { 1 }, { }&lt;br /&gt;
 [23:21:56.989278081] (+0.000007682) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989286043] (+0.000007962) sys_pipe: { 1 }, { fildes = 0xB77B9E8C }&lt;br /&gt;
 [23:21:56.989321802] (+0.000035759) exit_syscall: { 1 }, { ret = 0 }&lt;br /&gt;
 [23:21:56.989329345] (+0.000007543) sys_mmap_pgoff: { 1 }, { addr = 0x0, len = 10485760, prot = 3, flags = 131362, fd = 4294967295, pgoff = 0 }&lt;br /&gt;
 [23:21:56.989351694] (+0.000022349) exit_syscall: { 1 }, { ret = -1247805440 }&lt;br /&gt;
 [23:21:56.989432989] (+0.000081295) sys_clone: { 1 }, { clone_flags = 0x411, newsp = 0xB5EFFFE4, parent_tid = 0xFFFFFFFF, child_tid = 0x0 }&lt;br /&gt;
 [23:21:56.989477129] (+0.000044140) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 681660, vruntime = 43367983388 }&lt;br /&gt;
 [23:21:56.989486697] (+0.000009568) sched_migrate_task: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, prio = 20, orig_cpu = 1, dest_cpu = 1 }&lt;br /&gt;
 [23:21:56.989508418] (+0.000021721) hrtimer_init: { 1 }, { hrtimer = 3970832076, clockid = 1, mode = 1 }&lt;br /&gt;
 [23:21:56.989770462] (+0.000262044) hrtimer_cancel: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989771580] (+0.000001118) hrtimer_cancel: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989776957] (+0.000005377) hrtimer_expire_entry: { 1 }, { hrtimer = 3993865440, now = 79815980007057, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989778145] (+0.000001188) hrtimer_expire_entry: { 0 }, { hrtimer = 3993812192, now = 79815980008174, function = 3238465232 }&lt;br /&gt;
 [23:21:56.989791695] (+0.000013550) softirq_raise: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989795396] (+0.000003701) softirq_raise: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989800635] (+0.000005239) softirq_raise: { 0 }, { vec = 9 }&lt;br /&gt;
 [23:21:56.989807130] (+0.000006495) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 330710, vruntime = 43368314098 }&lt;br /&gt;
 [23:21:56.989809993] (+0.000002863) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 1015313, vruntime = 36976733240 }&lt;br /&gt;
 [23:21:56.989818514] (+0.000008521) hrtimer_expire_exit: { 0 }, { hrtimer = 3993812192 }&lt;br /&gt;
 [23:21:56.989819631] (+0.000001117) hrtimer_expire_exit: { 1 }, { hrtimer = 3993865440 }&lt;br /&gt;
 [23:21:56.989821866] (+0.000002235) hrtimer_start: { 0 }, { hrtimer = 3993812192, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989822984] (+0.000001118) hrtimer_start: { 1 }, { hrtimer = 3993865440, function = 3238465232, expires = 79815981000000, softexpires = 79815981000000 }&lt;br /&gt;
 [23:21:56.989832762] (+0.000009778) softirq_entry: { 1 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989833879] (+0.000001117) softirq_entry: { 0 }, { vec = 1 }&lt;br /&gt;
 [23:21:56.989838069] (+0.000004190) timer_cancel: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989839187] (+0.000001118) timer_cancel: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 [23:21:56.989841492] (+0.000002305) timer_expire_entry: { 1 }, { timer = 3993871956, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989842819] (+0.000001327) timer_expire_entry: { 0 }, { timer = 3993818708, now = 79515980, function = 3238277552 }&lt;br /&gt;
 [23:21:56.989854831] (+0.000012012) sched_stat_runtime: { 1 }, { comm = &amp;quot;lttng-consumerd&amp;quot;, tid = 1193, runtime = 49237, vruntime = 43368363335 }&lt;br /&gt;
 [23:21:56.989855949] (+0.000001118) sched_stat_runtime: { 0 }, { comm = &amp;quot;lttng-sessiond&amp;quot;, tid = 1181, runtime = 45121, vruntime = 36976778361 }&lt;br /&gt;
 [23:21:56.989861257] (+0.000005308) sched_stat_sleep: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, delay = 9451318 }&lt;br /&gt;
 [23:21:56.989862374] (+0.000001117) sched_stat_sleep: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, delay = 9958820 }&lt;br /&gt;
 [23:21:56.989868241] (+0.000005867) sched_wakeup: { 0 }, { comm = &amp;quot;kworker/0:0&amp;quot;, tid = 4, prio = 120, success = 1, target_cpu = 0 }&lt;br /&gt;
 [23:21:56.989869358] (+0.000001117) sched_wakeup: { 1 }, { comm = &amp;quot;kworker/1:1&amp;quot;, tid = 21, prio = 120, success = 1, target_cpu = 1 }&lt;br /&gt;
 [23:21:56.989877460] (+0.000008102) timer_expire_exit: { 1 }, { timer = 3993871956 }&lt;br /&gt;
 [23:21:56.989878577] (+0.000001117) timer_expire_exit: { 0 }, { timer = 3993818708 }&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
 .&lt;br /&gt;
&lt;br /&gt;
You can now safely destroy the trace session (note that this doesn&#039;t delete the trace - it&#039;s still there in ~/lttng-traces):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# lttng destroy&lt;br /&gt;
 Session auto-20121015-232120 destroyed at /home/root&lt;br /&gt;
&lt;br /&gt;
Note that the trace is saved in a directory of the same name as returned by &#039;lttng create&#039;, under the ~/lttng-traces directory (note that you can change this by supplying your own name to &#039;lttng create&#039;):&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al ~/lttng-traces&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 .&lt;br /&gt;
 drwxr-xr-x    5 root     root          1024 Oct 15 23:57 ..&lt;br /&gt;
 drwxrwx---    3 root     root          1024 Oct 15 23:21 auto-20121015-232120&lt;br /&gt;
&lt;br /&gt;
===== Manually copying a trace to the host and viewing it in Eclipse (i.e. using Eclipse without network support) =====&lt;br /&gt;
&lt;br /&gt;
If you already have an LTTng trace on a remote target and would like to view it in Eclipse on the host, you can easily copy it from the target to the host and import it into Eclipse to view it using the LTTng Eclipse plugin already bundled in the Eclipse (Juno SR1 or greater).&lt;br /&gt;
&lt;br /&gt;
Using the trace we created in the previous section, archive it and copy it to your host system:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~/lttng-traces# tar zcvf auto-20121015-232120.tar.gz auto-20121015-232120 &lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
 $ scp root@192.168.1.47:lttng-traces/auto-20121015-232120.tar.gz .&lt;br /&gt;
 root@192.168.1.47&#039;s password: &lt;br /&gt;
 auto-20121015-232120.tar.gz                                             100% 1566KB   1.5MB/s   00:01&lt;br /&gt;
&lt;br /&gt;
Unarchive it on the host:&lt;br /&gt;
&lt;br /&gt;
 $ gunzip -c auto-20121015-232120.tar.gz | tar xvf -&lt;br /&gt;
 auto-20121015-232120/&lt;br /&gt;
 auto-20121015-232120/kernel/&lt;br /&gt;
 auto-20121015-232120/kernel/metadata&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_1&lt;br /&gt;
 auto-20121015-232120/kernel/channel0_0&lt;br /&gt;
&lt;br /&gt;
We can now import the trace into Eclipse and view it:&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Project Explorer&#039; pane under the project you created, right click on the &#039;Traces&#039; item.&lt;br /&gt;
&lt;br /&gt;
* Select &#039;Import...&amp;quot; and in the dialog that&#039;s displayed:&lt;br /&gt;
* Browse the filesystem and find the select the &#039;kernel&#039; directory containing the trace you copied from the target e.g. auto-20121015-232120/kernel&lt;br /&gt;
* &#039;Checkmark&#039; the directory in the tree that&#039;s displayed for the trace&lt;br /&gt;
* Below that, select &#039;Common Trace Format: Kernel Trace&#039; for the &#039;Trace Type&#039;&lt;br /&gt;
* Press &#039;Finish&#039; to close the dialog&lt;br /&gt;
* Back in the &#039;Project Explorer&#039; pane, double-click on the &#039;kernel&#039; item for the trace you just imported under &#039;Traces&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You should now see your trace data displayed graphically in several different views in Eclipse:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Lttngmain0.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plugin to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
===== Collecting and viewing a trace in Eclipse =====&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;NOTE: This section on collecting traces remotely doesn&#039;t currently work because of Eclipse &#039;RSE&#039; connectivity problems. Manually tracing on the target, copying the trace files to the host, and viewing the trace in Eclipse on the host as outlined in previous steps does work however - please use the manual steps outlined above to view traces in Eclipse.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to trace a remote target, you also need to add a &#039;tracing&#039; group on the target and connect as a user who&#039;s part of that group e.g:&lt;br /&gt;
&lt;br /&gt;
 # adduser tomz&lt;br /&gt;
 # groupadd -r tracing&lt;br /&gt;
 # usermod -a -G tracing tomz&lt;br /&gt;
&lt;br /&gt;
* First, start eclipse and open the &#039;LTTng Kernel&#039; perspective by selecting the following menu item:&lt;br /&gt;
&lt;br /&gt;
 Window | Open Perspective | Other...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select &#039;LTTng Kernel&#039; from the list.&lt;br /&gt;
&lt;br /&gt;
* Back at the main menu, select the following menu item:&lt;br /&gt;
&lt;br /&gt;
 File | New | Project...&lt;br /&gt;
&lt;br /&gt;
* In the dialog box that opens, select the &#039;Tracing | Tracing Project&#039; wizard and press &#039;Next&amp;gt;&#039;.&lt;br /&gt;
&lt;br /&gt;
* Give the project a name and press &#039;Finish&#039;.&lt;br /&gt;
&lt;br /&gt;
That should result in an entry in the &#039;Project&#039; subwindow.&lt;br /&gt;
&lt;br /&gt;
* In the &#039;Control&#039; subwindow just below it, press &#039;New Connection&#039;.&lt;br /&gt;
&lt;br /&gt;
* Add a new connection, giving it the hostname or IP address of the target system.&lt;br /&gt;
&lt;br /&gt;
Also provide the username and password of a qualified user (a member of the &#039;tracing&#039; group) or root account on the target system.&lt;br /&gt;
&lt;br /&gt;
Also, provide appropriate answers to whatever else is asked for e.g. &#039;secure storage password&#039; can be anything you want&lt;br /&gt;
&lt;br /&gt;
If you get an &#039;RSE Error&#039; it may be due to proxies.  It may be possible to get around the problem by changing the following setting:&lt;br /&gt;
&lt;br /&gt;
 Window | Preferences | Network Connections&lt;br /&gt;
&lt;br /&gt;
Switch &#039;Active Provider&#039; to &#039;Direct&#039;&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
&lt;br /&gt;
There doesn&#039;t seem to be any current documentation covering LTTng 2.0, but maybe that&#039;s because the project is in transition.  The LTTng 2.0 website, however, is here: [http://lttng.org/lttng2.0 LTTng Project]&lt;br /&gt;
&lt;br /&gt;
You can access extensive help information on how to use the LTTng plug-in to search and analyze captured traces via the Eclipse help system:&lt;br /&gt;
&lt;br /&gt;
 Help | Help Contents | LTTng Plug-in User Guide&lt;br /&gt;
&lt;br /&gt;
=== blktrace ===&lt;br /&gt;
&lt;br /&gt;
blktrace is a tool for tracing and reporting low-level disk I/O.  blktrace provides the tracing half of the equation; its output can be piped into the blkparse program, which renders the data in a human-readable form and does some basic analysis: &lt;br /&gt;
&lt;br /&gt;
==== Setup ====&lt;br /&gt;
For this section, we&#039;ll assume you&#039;ve already performed the basic setup outlined in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup ] section.&lt;br /&gt;
&lt;br /&gt;
blktrace is an application that runs on the target system.  You can run the entire blktrace and blkparse pipeline on the target, or you can run blktrace in &#039;listen&#039; mode on the target and have blktrace and blkparse collect and analyze the data on the host (see the section on [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#Using_blktrace_remotely using blktrace remotely] below).  For the rest of this section we assume you&#039;ve ssh&#039;ed to the host and will be running blkrace on the target.&lt;br /&gt;
&lt;br /&gt;
==== Basic Usage ====&lt;br /&gt;
&lt;br /&gt;
To record a trace, simply run the &#039;blktrace&#039; command, giving it the name of the block device you want to trace activity on:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
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 simply dumps them to userspace for blkparse to merge and sort later).  &lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7082 events,      332 KiB data&lt;br /&gt;
  CPU  1:                 1578 events,       74 KiB data&lt;br /&gt;
  Total:                  8660 events (dropped 0),      406 KiB data&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# ls -al&lt;br /&gt;
 drwxr-xr-x    6 root     root          1024 Oct 27 22:39 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 -rw-r--r--    1 root     root        339938 Oct 27 22:40 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root         75753 Oct 27 22:40 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
To view the trace events, simply invoke &#039;blkparse&#039; in the directory containing the trace files, giving it the device name that forms the first part of the filenames: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blkparse sdc&lt;br /&gt;
&lt;br /&gt;
  8,32   1        1     0.000000000  1225  Q  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        2     0.000025213  1225  G  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        3     0.000033384  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        4     0.000043301  1225  I  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000057270     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1        0     0.000064813     0  m   N cfq1225 add_to_rr&lt;br /&gt;
  8,32   1        5     0.000076336  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000088559     0  m   N cfq workload slice:150&lt;br /&gt;
  8,32   1        0     0.000097359     0  m   N cfq1225 set_active wl_prio:0 wl_type:1&lt;br /&gt;
  8,32   1        0     0.000104063     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000112584     0  m   N cfq1225 fifo=  (null)&lt;br /&gt;
  8,32   1        0     0.000118730     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000127390     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000133536     0  m   N cfq1225 activate rq, drv=1&lt;br /&gt;
  8,32   1        6     0.000136889  1225  D  WS 3417048 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        7     0.000360381  1225  Q  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        8     0.000377422  1225  G  WS 3417056 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        9     0.000388876  1225  P   N [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       10     0.000397886  1225  Q  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       11     0.000404800  1225  M  WS 3417064 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       12     0.000412343  1225  Q  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       13     0.000416533  1225  M  WS 3417072 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       14     0.000422121  1225  Q  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       15     0.000425194  1225  M  WS 3417080 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       16     0.000431968  1225  Q  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       17     0.000435251  1225  M  WS 3417088 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       18     0.000440279  1225  Q  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       19     0.000443911  1225  M  WS 3417096 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       20     0.000450336  1225  Q  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       21     0.000454038  1225  M  WS 3417104 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       22     0.000462070  1225  Q  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       23     0.000465422  1225  M  WS 3417112 + 8 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1       24     0.000474222  1225  I  WS 3417056 + 64 [jbd2/sdc-8]&lt;br /&gt;
  8,32   1        0     0.000483022     0  m   N cfq1225 insert_request&lt;br /&gt;
  8,32   1       25     0.000489727  1225  U   N [jbd2/sdc-8] 1&lt;br /&gt;
  8,32   1        0     0.000498457     0  m   N cfq1225 Not idling. st-&amp;gt;count:1&lt;br /&gt;
  8,32   1        0     0.000503765     0  m   N cfq1225 dispatch_insert&lt;br /&gt;
  8,32   1        0     0.000512914     0  m   N cfq1225 dispatched a request&lt;br /&gt;
  8,32   1        0     0.000518851     0  m   N cfq1225 activate rq, drv=2&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0    58.515006138     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0     2024    58.516603269     3  C  WS 3156992 + 16 [0]&lt;br /&gt;
  8,32   0        0    58.516626736     0  m   N cfq3551 complete rqnoidle 1&lt;br /&gt;
  8,32   0        0    58.516634558     0  m   N cfq3551 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0    58.516636933     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0    58.516971613     0  m   N cfq3551 slice expired t=0&lt;br /&gt;
  8,32   1        0    58.516982089     0  m   N cfq3551 sl_used=13 disp=6 charge=13 iops=0 sect=80&lt;br /&gt;
  8,32   1        0    58.516985511     0  m   N cfq3551 del_from_rr&lt;br /&gt;
  8,32   1        0    58.516990819     0  m   N cfq3551 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         331,   26,284KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      485,   40,484KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      511,   41,000KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           13,      160KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            23        	 Timer unplugs:           0&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         249,   15,800KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:       42,    1,600KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       16,    1,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           40,      276KiB&lt;br /&gt;
  Read depth:             0        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            30        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         580,   42,084KiB&lt;br /&gt;
  Read Dispatches:        0,        0KiB	 Write Dispatches:      527,   42,084KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:      527,   42,084KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:           53,      436KiB&lt;br /&gt;
  IO unplugs:            53        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 0KiB/s / 719KiB/s&lt;br /&gt;
 Events (sdc): 6,592 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
 Input file sdc.blktrace.0 added&lt;br /&gt;
 Input file sdc.blktrace.1 added&lt;br /&gt;
&lt;br /&gt;
The report shows each event that was found in the blktrace data, along with a summary of the overall block I/O traffic during the run.  You can look at the [http://linux.die.net/man/1/blkparse blkparse] manpage to learn the meaning of each field displayed in the trace listing.&lt;br /&gt;
&lt;br /&gt;
===== Live Mode =====&lt;br /&gt;
blktrace and blkparse are designed from the ground up to be able to operate together in a &#039;pipe mode&#039; where the stdout of blktrace can be fed directly into the stdin of blkparse:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace /dev/sdc -o - | blkparse -i -&lt;br /&gt;
&lt;br /&gt;
This enables long-lived tracing sessions to run without writing anything to disk, and allows the user to look for certain conditions in the trace data in &#039;real-time&#039; by viewing the trace output as it scrolls by on the screen or by passing it along to yet another program in the pipeline such as grep which can be used to identify and capture conditions of interest.&lt;br /&gt;
&lt;br /&gt;
There&#039;s actually another blktrace command that implements the above pipeline as a single command, so the user doesn&#039;t have to bother typing in the above command sequence: &lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# btrace /dev/sdc&lt;br /&gt;
&lt;br /&gt;
===== Using blktrace remotely =====&lt;br /&gt;
&lt;br /&gt;
Because blktrace traces block I/O and at the same time normally writes its trace data to a block device, and in general because it&#039;s not really a great idea to make the device being traced the same as the device the tracer writes to, blktrace provides a way to trace without perturbing the traced device at all by providing native support for sending all trace data over the network. &lt;br /&gt;
&lt;br /&gt;
To have blktrace operate in this mode, start blktrace on the target system being traced with the -l option, along with the device to trace:&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:~# blktrace -l /dev/sdc&lt;br /&gt;
 server: waiting for connections...&lt;br /&gt;
&lt;br /&gt;
On the host system, use the -h option to connect to the target system, also passing it the device to trace:&lt;br /&gt;
&lt;br /&gt;
 $ blktrace -d /dev/sdc -h 192.168.1.43&lt;br /&gt;
 blktrace: connecting to 192.168.1.43&lt;br /&gt;
 blktrace: connected!&lt;br /&gt;
&lt;br /&gt;
On the target system, you should see this:&lt;br /&gt;
&lt;br /&gt;
 server: connection from 192.168.1.43&lt;br /&gt;
&lt;br /&gt;
In another shell, execute a workload you want to trace.&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/media/sdc# rm linux-2.6.19.2.tar.bz2; wget http://downloads.yoctoproject.org/mirror/sources/linux-2.6.19.2.tar.bz2; sync&lt;br /&gt;
 Connecting to downloads.yoctoproject.org (140.211.169.59:80)&lt;br /&gt;
 linux-2.6.19.2.tar.b 100% |*******************************| 41727k  0:00:00 ETA&lt;br /&gt;
&lt;br /&gt;
When it&#039;s done, do a Ctrl-C on the host system to stop the trace:&lt;br /&gt;
&lt;br /&gt;
 ^C=== sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
On the target system, you should also see a trace summary for the trace just ended:&lt;br /&gt;
&lt;br /&gt;
 server: end of run for 192.168.1.43:sdc&lt;br /&gt;
 === sdc ===&lt;br /&gt;
  CPU  0:                 7691 events,      361 KiB data&lt;br /&gt;
  CPU  1:                 4109 events,      193 KiB data&lt;br /&gt;
  Total:                 11800 events (dropped 0),      554 KiB data&lt;br /&gt;
&lt;br /&gt;
The blktrace instance on the host will save the target output inside a hostname-timestamp directory:&lt;br /&gt;
&lt;br /&gt;
 $ ls -al&lt;br /&gt;
 drwxr-xr-x   10 root     root          1024 Oct 28 02:40 .&lt;br /&gt;
 drwxr-sr-x    4 root     root          1024 Oct 26 18:24 ..&lt;br /&gt;
 drwxr-xr-x    2 root     root          1024 Oct 28 02:40 192.168.1.43-2012-10-28-02:40:56&lt;br /&gt;
&lt;br /&gt;
cd into that directory to see the output files:&lt;br /&gt;
&lt;br /&gt;
 $ ls -l&lt;br /&gt;
 -rw-r--r--    1 root     root        369193 Oct 28 02:44 sdc.blktrace.0&lt;br /&gt;
 -rw-r--r--    1 root     root        197278 Oct 28 02:44 sdc.blktrace.1&lt;br /&gt;
&lt;br /&gt;
And run blkparse on the host system using the device name:&lt;br /&gt;
&lt;br /&gt;
 $ blkparse sdc&lt;br /&gt;
 &lt;br /&gt;
  8,32   1        1     0.000000000  1263  Q  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000036038     0  m   N cfq1263 alloced&lt;br /&gt;
  8,32   1        2     0.000039390  1263  G  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        3     0.000049168  1263  I  RM 6016 + 8 [ls]&lt;br /&gt;
  8,32   1        0     0.000056152     0  m   N cfq1263 insert_request&lt;br /&gt;
  8,32   1        0     0.000061600     0  m   N cfq1263 add_to_rr&lt;br /&gt;
  8,32   1        0     0.000075498     0  m   N cfq workload slice:300&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  .&lt;br /&gt;
  8,32   0        0   177.266385696     0  m   N cfq1267 arm_idle: 8 group_idle: 0&lt;br /&gt;
  8,32   0        0   177.266388140     0  m   N cfq schedule dispatch&lt;br /&gt;
  8,32   1        0   177.266679239     0  m   N cfq1267 slice expired t=0&lt;br /&gt;
  8,32   1        0   177.266689297     0  m   N cfq1267 sl_used=9 disp=6 charge=9 iops=0 sect=56&lt;br /&gt;
  8,32   1        0   177.266692649     0  m   N cfq1267 del_from_rr&lt;br /&gt;
  8,32   1        0   177.266696560     0  m   N cfq1267 put_queue&lt;br /&gt;
 &lt;br /&gt;
 CPU0 (sdc):&lt;br /&gt;
  Reads Queued:           0,        0KiB	 Writes Queued:         270,   21,708KiB&lt;br /&gt;
  Read Dispatches:       59,    2,628KiB	 Write Dispatches:      495,   39,964KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      543,   41,596KiB&lt;br /&gt;
  Read Merges:            0,        0KiB	 Write Merges:            9,      344KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            20        	 Timer unplugs:           1&lt;br /&gt;
 CPU1 (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         381,   20,652KiB&lt;br /&gt;
  Read Dispatches:       31,      124KiB	 Write Dispatches:       59,    2,396KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:        0,        0KiB	 Writes Completed:       11,      764KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           88,      448KiB&lt;br /&gt;
  Read depth:             2        	 Write depth:             2&lt;br /&gt;
  IO unplugs:            52        	 Timer unplugs:           0&lt;br /&gt;
 &lt;br /&gt;
 Total (sdc):&lt;br /&gt;
  Reads Queued:         688,    2,752KiB	 Writes Queued:         651,   42,360KiB&lt;br /&gt;
  Read Dispatches:       90,    2,752KiB	 Write Dispatches:      554,   42,360KiB&lt;br /&gt;
  Reads Requeued:         0		 Writes Requeued:         0&lt;br /&gt;
  Reads Completed:       90,    2,752KiB	 Writes Completed:      554,   42,360KiB&lt;br /&gt;
  Read Merges:          598,    2,392KiB	 Write Merges:           97,      792KiB&lt;br /&gt;
  IO unplugs:            72        	 Timer unplugs:           1&lt;br /&gt;
 &lt;br /&gt;
 Throughput (R/W): 15KiB/s / 238KiB/s&lt;br /&gt;
 Events (sdc): 9,301 entries&lt;br /&gt;
 Skips: 0 forward (0 -   0.0%)&lt;br /&gt;
&lt;br /&gt;
You should see the trace events and summary just as you would have if you&#039;d run the same command on the target.&lt;br /&gt;
&lt;br /&gt;
===== Tracing Block I/O via &#039;ftrace&#039; =====&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 1 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat available_tracers &lt;br /&gt;
 blk function_graph function nop&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo blk &amp;gt; current_tracer&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat /media/sdc/testfile.txt&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# cat trace_pipe &lt;br /&gt;
             cat-3587  [001] d..1  3023.276361:   8,32   Q   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276410:   8,32   m   N cfq3587 alloced&lt;br /&gt;
             cat-3587  [001] d..1  3023.276415:   8,32   G   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276424:   8,32   P   N [cat]&lt;br /&gt;
             cat-3587  [001] d..2  3023.276432:   8,32   I   R 1699848 + 8 [cat]&lt;br /&gt;
             cat-3587  [001] d..1  3023.276439:   8,32   m   N cfq3587 insert_request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276445:   8,32   m   N cfq3587 add_to_rr&lt;br /&gt;
             cat-3587  [001] d..2  3023.276454:   8,32   U   N [cat] 1&lt;br /&gt;
             cat-3587  [001] d..1  3023.276464:   8,32   m   N cfq workload slice:150&lt;br /&gt;
             cat-3587  [001] d..1  3023.276471:   8,32   m   N cfq3587 set_active wl_prio:0 wl_type:2&lt;br /&gt;
             cat-3587  [001] d..1  3023.276478:   8,32   m   N cfq3587 fifo=  (null)&lt;br /&gt;
             cat-3587  [001] d..1  3023.276483:   8,32   m   N cfq3587 dispatch_insert&lt;br /&gt;
             cat-3587  [001] d..1  3023.276490:   8,32   m   N cfq3587 dispatched a request&lt;br /&gt;
             cat-3587  [001] d..1  3023.276497:   8,32   m   N cfq3587 activate rq, drv=1&lt;br /&gt;
             cat-3587  [001] d..2  3023.276500:   8,32   D   R 1699848 + 8 [cat]&lt;br /&gt;
&lt;br /&gt;
 root@crownbay:/sys/kernel/debug/tracing# echo 0 &amp;gt; /sys/block/sdc/trace/enable&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
Online versions of the man pages for the commands discussed in this section can be found here:&lt;br /&gt;
&lt;br /&gt;
*http://linux.die.net/man/8/blktrace&lt;br /&gt;
*http://linux.die.net/man/1/blkparse&lt;br /&gt;
*http://linux.die.net/man/8/btrace&lt;br /&gt;
&lt;br /&gt;
The above manpages, along with manpages for the other blktrace utilities (btt, blkiomon, etc) can be found in the /doc directory of the blktrace tools git repo:&lt;br /&gt;
&lt;br /&gt;
 $ git clone git://git.kernel.dk/blktrace.git&lt;br /&gt;
&lt;br /&gt;
=== systemtap ===&lt;br /&gt;
&lt;br /&gt;
SystemTap is a system-wide script-based tracing and profiling tool.&lt;br /&gt;
&lt;br /&gt;
SystemTap scripts are C-like programs that are executed in the kernel to gather/print/aggregate data extracted from the context they end up being invoked under.&lt;br /&gt;
&lt;br /&gt;
For example, this probe from the SystemTap tutorial [http://sourceware.org/systemtap/tutorial/] simply prints a line every time any process on the system open()s a file.  For each line, it prints the executable name of the program that opened the file, along with its pid, and the name of the file it opened (or tried to open), which it extracts from the open syscall&#039;s argstr.&lt;br /&gt;
&lt;br /&gt;
 probe syscall.open&lt;br /&gt;
 {&lt;br /&gt;
         printf (&amp;quot;%s(%d) open (%s)\n&amp;quot;, execname(), pid(), argstr)&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 probe timer.ms(4000) # after 4 seconds&lt;br /&gt;
 {&lt;br /&gt;
         exit ()&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
Normally, to execute this probe, you&#039;d simply 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:&lt;br /&gt;
&lt;br /&gt;
 # stap trace_open.stp&lt;br /&gt;
&lt;br /&gt;
What systemtap does under the covers to run this probe is 1) parse and convert the probe to an equivalent &#039;C&#039; form, 2) compile the &#039;C&#039; form into a kernel module, 3) insert the module into the kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
&lt;br /&gt;
In order to accomplish steps 1 and 2, the &#039;stap&#039; program needs access to the kernel build system that produced the kernel that the probed system is running.  In the case of a typical embedded system (the &#039;target&#039;), the kernel build system unfortunately isn&#039;t typically part of the image running on the target.  It is normally available on the &#039;host&#039; system that produced the target image however; in such cases, steps 1 and 2 are executed on the host system, and steps 3 and 4 are executed on the target system, using only the systemtap &#039;runtime&#039;.&lt;br /&gt;
&lt;br /&gt;
The systemtap support in Yocto assumes that only steps 3 and 4 are run on the target; it is possible to do everything on the target, but this section assumes only the typical embedded use-case.&lt;br /&gt;
&lt;br /&gt;
So basically what you need to do in order to run a systemtap script on the target is to 1) on the host system, compile the probe into a kernel module that makes sense to the target, 2) copy the module onto the target system and 3) insert the module into the target kernel, which arms it, and 4) collect the data generated by the probe and display it to the user.&lt;br /&gt;
 &lt;br /&gt;
==== Setup ====&lt;br /&gt;
Those are a lot of steps and a lot of details, but fortunately Yocto includes a script called &#039;crosstap&#039; that will take care of those details, allowing you to simply execute a systemtap script on the remote target, with arguments if necessary.&lt;br /&gt;
&lt;br /&gt;
In order to do this from a remote host, however, you need to have access to the build for the image you booted.  The &#039;crosstap&#039; script provides details on how to do this if you run the script on the host without having done a build:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.1.88 trace_open.stp&lt;br /&gt;
 &lt;br /&gt;
 Error: No target kernel build found.&lt;br /&gt;
 Did you forget to create a local build of your image?&lt;br /&gt;
 &lt;br /&gt;
 &#039;crosstap&#039; requires a local sdk build of the target system&lt;br /&gt;
 (or a build that includes &#039;tools-profile&#039;) in order to build&lt;br /&gt;
 kernel modules that can probe the target system.&lt;br /&gt;
 &lt;br /&gt;
 Practically speaking, that means you need to do the following:&lt;br /&gt;
  - If you&#039;re running a pre-built image, download the release&lt;br /&gt;
    and/or BSP tarballs used to build the image.&lt;br /&gt;
  - If you&#039;re working from git sources, just clone the metadata&lt;br /&gt;
    and BSP layers needed to build the image you&#039;ll be booting.&lt;br /&gt;
  - Make sure you&#039;re properly set up to build a new image (see&lt;br /&gt;
    the BSP README and/or the widely available basic documentation&lt;br /&gt;
    that discusses how to build images).&lt;br /&gt;
  - Build an -sdk version of the image e.g.:&lt;br /&gt;
      $ bitbake core-image-sato-sdk&lt;br /&gt;
  OR&lt;br /&gt;
  - Build a non-sdk image but include the profiling tools:&lt;br /&gt;
      [ edit local.conf and add &#039;tools-profile&#039; to the end of&lt;br /&gt;
        the EXTRA_IMAGE_FEATURES variable ]&lt;br /&gt;
      $ bitbake core-image-sato&lt;br /&gt;
 &lt;br /&gt;
  [ NOTE that &#039;crosstap&#039; needs to be able to ssh into the target&lt;br /&gt;
    system, which isn&#039;t enabled by default in -minimal images. ]&lt;br /&gt;
 &lt;br /&gt;
 Once you&#039;ve build the image on the host system, you&#039;re ready to&lt;br /&gt;
 boot it (or the equivalent pre-built image) and use &#039;crosstap&#039;&lt;br /&gt;
 to probe it (you need to source the environment as usual first):&lt;br /&gt;
 &lt;br /&gt;
    $ source oe-init-build-env&lt;br /&gt;
    $ cd ~/my/systemtap/scripts&lt;br /&gt;
    $ crosstap root@192.168.1.xxx myscript.stp&lt;br /&gt;
&lt;br /&gt;
So essentially what you need to do is build an SDK image or image with &#039;tools-profile&#039; as detailed in the [https://wiki.yoctoproject.org/wiki/Tracing_and_Profiling#General_Setup General Setup] section of this wiki, and boot the resulting target image.&lt;br /&gt;
&lt;br /&gt;
NOTE: if you have a build directory containing multiple machines, you need to have the MACHINE you&#039;re connecting to selected in local.conf, and the kernel in that machine&#039;s build directory must match the kernel on the booted system exactly, or you&#039;ll get the above &#039;crosstap&#039; message when you try to invoke a script.&lt;br /&gt;
&lt;br /&gt;
==== Running a script on the target ====&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you should be able to run a systemtap script on the target:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/yocto&lt;br /&gt;
 $ source oe-init-build-env&lt;br /&gt;
&lt;br /&gt;
 ### Shell environment set up for builds. ###&lt;br /&gt;
 &lt;br /&gt;
 You can now run &#039;bitbake &amp;lt;target&amp;gt;&#039;&lt;br /&gt;
 &lt;br /&gt;
 Common targets are:&lt;br /&gt;
    core-image-minimal&lt;br /&gt;
    core-image-sato&lt;br /&gt;
    meta-toolchain&lt;br /&gt;
    meta-toolchain-sdk&lt;br /&gt;
    adt-installer&lt;br /&gt;
    meta-ide-support&lt;br /&gt;
 &lt;br /&gt;
 You can also run generated qemu images with a command like &#039;runqemu qemux86&#039;&lt;br /&gt;
&lt;br /&gt;
Once you&#039;ve done that, you can cd to whatever directory contains your scripts and use &#039;crosstap&#039; to run the script:&lt;br /&gt;
&lt;br /&gt;
 $ cd /path/to/my/systemap/script&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp&lt;br /&gt;
&lt;br /&gt;
If you get an error connecting to the target e.g.:&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 error establishing ssh connection on remote &#039;root@192.168.7.2&#039;&lt;br /&gt;
&lt;br /&gt;
Try ssh&#039;ing to the target and see what happens:&lt;br /&gt;
&lt;br /&gt;
 $ ssh root@192.168.7.2&lt;br /&gt;
&lt;br /&gt;
A lot of the time, connection problems are due specifying a wrong IP address or having a &#039;host key verification error&#039;.&lt;br /&gt;
&lt;br /&gt;
If everything worked as planned, you should see something like this (enter the password when prompted, or press enter if its set up to use no password):&lt;br /&gt;
&lt;br /&gt;
 $ crosstap root@192.168.7.2 trace_open.stp &lt;br /&gt;
 root@192.168.7.2&#039;s password: &lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vte3FS2LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
 matchbox-termin(1036) open (&amp;quot;/tmp/vteJMC7LW&amp;quot;, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600)&lt;br /&gt;
&lt;br /&gt;
==== Documentation ====&lt;br /&gt;
The SystemTap language reference can be found here: [http://sourceware.org/systemtap/langref/ SystemTap Language Reference]&lt;br /&gt;
&lt;br /&gt;
Links to other SystemTap documents, tutorials, and examples can be found here: [http://sourceware.org/systemtap/documentation.html SystemTap documentation page]&lt;br /&gt;
&lt;br /&gt;
== Real-world Examples  ==&lt;br /&gt;
=== Slow write speed on live images ===&lt;br /&gt;
In one of our previous releases (denzil), users noticed that booting off of a live image and writing to disk was noticeably slower.  This included the boot itself, especially the first one, since first boots tend to do a significant amount of writing due to certain post-install scripts.&lt;br /&gt;
&lt;br /&gt;
The problem (and solution) was discovered by using the Yocto tracing tools, in this case &#039;perf stat&#039;, &#039;perf script&#039;, &#039;perf record&#039; and &#039;perf report&#039;.&lt;br /&gt;
&lt;br /&gt;
See all the unvarnished details of how this bug was diagnosed and solved here: [https://bugzilla.yoctoproject.org/show_bug.cgi?id=3049 Yocto Bug #3049]&lt;/div&gt;</summary>
		<author><name>Tzanussi</name></author>
	</entry>
</feed>